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)
6363 char * loc ;
6464 int4 user_id ;
6565 bool use_super , use_createdb ;
66-
6766 Relation pg_database_rel ;
6867 HeapTuple tuple ;
6968 TupleDesc pg_database_dsc ;
70-
7169 Datum new_record [Natts_pg_database ];
7270 char new_record_nulls [Natts_pg_database ] = { ' ' , ' ' , ' ' , ' ' };
7371
74-
7572 if (!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
7875 if (!use_createdb && !use_super )
79- elog (ERROR , "CREATE DATABASE: Permission denied. " );
76+ elog (ERROR , "CREATE DATABASE: Permission denied" );
8077
8178 if (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 */
8986 if (dbpath == NULL )
@@ -95,13 +92,11 @@ createdb(const char *dbname, const char *dbpath, int encoding)
9592 elog (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
144139 if (mkdir (loc , S_IRWXU ) != 0 ) {
145- UserAbortTransactionBlock ();
146140 elog (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)
152146 int ret ;
153147 snprintf (buf , sizeof (buf ), "rm -rf '%s'" , loc );
154148 ret = system (buf );
155- UserAbortTransactionBlock ();
156149 if (ret == 0 )
157- elog (ERROR , "CREATE DATABASE: Could not initialize database directory. " );
150+ elog (ERROR , "CREATE DATABASE: Could not initialize database directory" );
158151 else
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)
178168 char * path ,
179169 dbpath [MAXPGPATH ],
180170 buf [MAXPGPATH + 100 ];
181-
182171 Relation pgdbrel ;
183172 HeapScanDesc pgdbscan ;
184173 ScanKeyData key ;
@@ -187,36 +176,33 @@ dropdb(const char *dbname)
187176 AssertArg (dbname );
188177
189178 if (strcmp (dbname , "template1" ) == 0 )
190- elog (ERROR , "DROP DATABASE: May not be executed on the template database. " );
179+ elog (ERROR , "DROP DATABASE: May not be executed on the template1 database" );
191180
192181 if (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
195187 if (!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
198190 if (!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
201193 if (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
208196 path = ExpandDatabasePath (dbpath );
209197 if (path == NULL )
210198 elog (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 */
235221 if (DatabaseHasActiveBackends (db_id )) {
236222 heap_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)
250235 if (!HeapTupleIsValid (tup ))
251236 {
252237 heap_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" ,
257241 dbname );
258242 }
259243
@@ -282,11 +266,8 @@ dropdb(const char *dbname)
282266 * Remove the database's subdirectory and everything in it.
283267 */
284268 snprintf (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
0 commit comments