88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.50 2000/01/26 05:56:13 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.51 2000/03/15 06:50:51 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -63,27 +63,24 @@ createdb(const char *dbname, const char *dbpath, int encoding)
6363char * loc ;
6464int4 user_id ;
6565bool use_super ,use_createdb ;
66-
6766Relation pg_database_rel ;
6867HeapTuple tuple ;
6968TupleDesc pg_database_dsc ;
70-
7169Datum new_record [Natts_pg_database ];
7270char new_record_nulls [Natts_pg_database ]= {' ' ,' ' ,' ' ,' ' };
7371
74-
7572if (!get_user_info (GetPgUserName (),& user_id ,& use_super ,& use_createdb ))
76- elog (ERROR ,"Current user name is invalid. " );
73+ elog (ERROR ,"Current user name is invalid" );
7774
7875if (!use_createdb && !use_super )
79- elog (ERROR ,"CREATE DATABASE: Permission denied. " );
76+ elog (ERROR ,"CREATE DATABASE: Permission denied" );
8077
8178if (get_db_info (dbname ,NULL ,NULL ,NULL ))
82- elog (ERROR ,"CREATE DATABASE: Database \"%s\" already exists. " ,dbname );
79+ elog (ERROR ,"CREATE DATABASE: Database \"%s\" already exists" ,dbname );
8380
84- /* close virtual file descriptors so the kernel has more available for
85- the system() calls */
86- closeAllVfds ( );
81+ /* don't call this in a transaction block */
82+ if ( IsTransactionBlock ())
83+ elog ( ERROR , "CREATE DATABASE: May not be called in a transaction block" );
8784
8885/* Generate directory name for the new database */
8986if (dbpath == NULL )
@@ -95,13 +92,11 @@ createdb(const char *dbname, const char *dbpath, int encoding)
9592elog (ERROR ,
9693"The database path '%s' is invalid. "
9794"This may be due to a character that is not allowed or because the chosen "
98- "path isn't permitted for databases. " ,dbpath );
95+ "path isn't permitted for databases" ,dbpath );
9996
100- /* don't call this in a transaction block */
101- if (IsTransactionBlock ())
102- elog (ERROR ,"CREATE DATABASE: May not be called in a transaction block." );
103- else
104- BeginTransactionBlock ();
97+ /* close virtual file descriptors so the kernel has more available for
98+ the system() calls */
99+ closeAllVfds ();
105100
106101/*
107102 * Insert a new tuple into pg_database
@@ -142,7 +137,6 @@ createdb(const char *dbname, const char *dbpath, int encoding)
142137/* Copy the template database to the new location */
143138
144139if (mkdir (loc ,S_IRWXU )!= 0 ) {
145- UserAbortTransactionBlock ();
146140elog (ERROR ,"CREATE DATABASE: Unable to create database directory '%s': %s" ,loc ,strerror (errno ));
147141 }
148142
@@ -152,15 +146,11 @@ createdb(const char *dbname, const char *dbpath, int encoding)
152146int ret ;
153147snprintf (buf ,sizeof (buf ),"rm -rf '%s'" ,loc );
154148ret = system (buf );
155- UserAbortTransactionBlock ();
156149if (ret == 0 )
157- elog (ERROR ,"CREATE DATABASE: Could not initialize database directory. " );
150+ elog (ERROR ,"CREATE DATABASE: Could not initialize database directory" );
158151else
159- elog (ERROR ,"CREATE DATABASE: Could not initialize database directory. Delete failed as well. " );
152+ elog (ERROR ,"CREATE DATABASE: Could not initialize database directory. Delete failed as well" );
160153 }
161-
162- if (IsTransactionBlock ())
163- EndTransactionBlock ();
164154}
165155
166156
@@ -178,7 +168,6 @@ dropdb(const char *dbname)
178168char * path ,
179169dbpath [MAXPGPATH ],
180170buf [MAXPGPATH + 100 ];
181-
182171Relation pgdbrel ;
183172HeapScanDesc pgdbscan ;
184173ScanKeyData key ;
@@ -187,36 +176,33 @@ dropdb(const char *dbname)
187176AssertArg (dbname );
188177
189178if (strcmp (dbname ,"template1" )== 0 )
190- elog (ERROR ,"DROP DATABASE: May not be executed on thetemplate database. " );
179+ elog (ERROR ,"DROP DATABASE: May not be executed on thetemplate1 database" );
191180
192181if (strcmp (dbname ,DatabaseName )== 0 )
193- elog (ERROR ,"DROP DATABASE: Cannot be executed on the currently open database." );
182+ elog (ERROR ,"DROP DATABASE: Cannot be executed on the currently open database" );
183+
184+ if (IsTransactionBlock ())
185+ elog (ERROR ,"DROP DATABASE: May not be called in a transaction block" );
194186
195187if (!get_user_info (GetPgUserName (),& user_id ,& use_super ,NULL ))
196- elog (ERROR ,"Current user name is invalid. " );
188+ elog (ERROR ,"Current user name is invalid" );
197189
198190if (!get_db_info (dbname ,dbpath ,& db_id ,& db_owner ))
199- elog (ERROR ,"DROP DATABASE: Database \"%s\" does not exist. " ,dbname );
191+ elog (ERROR ,"DROP DATABASE: Database \"%s\" does not exist" ,dbname );
200192
201193if (user_id != db_owner && !use_super )
202- elog (ERROR ,"DROP DATABASE: Permission denied." );
203-
204- /* close virtual file descriptors so the kernel has more available for
205- the system() calls */
206- closeAllVfds ();
194+ elog (ERROR ,"DROP DATABASE: Permission denied" );
207195
208196path = ExpandDatabasePath (dbpath );
209197if (path == NULL )
210198elog (ERROR ,
211199"The database path '%s' is invalid. "
212200"This may be due to a character that is not allowed or because the chosen "
213- "path isn't permitted for databases. " ,path );
201+ "path isn't permitted for databases" ,path );
214202
215- /* don't call this in a transaction block */
216- if (IsTransactionBlock ())
217- elog (ERROR ,"DROP DATABASE: May not be called in a transaction block." );
218- else
219- BeginTransactionBlock ();
203+ /* close virtual file descriptors so the kernel has more available for
204+ the system() calls */
205+ closeAllVfds ();
220206
221207/*
222208 * Obtain exclusive lock on pg_database. We need this to ensure
@@ -234,8 +220,7 @@ dropdb(const char *dbname)
234220 */
235221if (DatabaseHasActiveBackends (db_id )) {
236222heap_close (pgdbrel ,AccessExclusiveLock );
237- UserAbortTransactionBlock ();
238- elog (ERROR ,"DROP DATABASE: Database \"%s\" is being accessed by other users." ,dbname );
223+ elog (ERROR ,"DROP DATABASE: Database \"%s\" is being accessed by other users" ,dbname );
239224 }
240225
241226/*
@@ -250,10 +235,9 @@ dropdb(const char *dbname)
250235if (!HeapTupleIsValid (tup ))
251236{
252237heap_close (pgdbrel ,AccessExclusiveLock );
253- UserAbortTransactionBlock ();
254238/* This error should never come up since the existence of the
255239 database is checked earlier */
256- elog (ERROR ,"DROP DATABASE: Database \"%s\" doesn't exist despite earlier reports to the contrary. " ,
240+ elog (ERROR ,"DROP DATABASE: Database \"%s\" doesn't exist despite earlier reports to the contrary" ,
257241dbname );
258242}
259243
@@ -282,11 +266,8 @@ dropdb(const char *dbname)
282266 * Remove the database's subdirectory and everything in it.
283267 */
284268snprintf (buf ,sizeof (buf ),"rm -rf '%s'" ,path );
285- if (system (buf )!= 0 )
286- elog (NOTICE ,"DROP DATABASE: The database directory '%s' could not be removed." ,path );
287-
288- if (IsTransactionBlock ())
289- EndTransactionBlock ();
269+ if (system (buf )!= 0 )
270+ elog (NOTICE ,"DROP DATABASE: The database directory '%s' could not be removed" ,path );
290271}
291272
292273