88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.61 2000/10/16 14:52:03 vadim Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.62 2000/10/22 17:55:36 pjw Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -44,7 +44,6 @@ static bool
4444 get_db_info (const char * name , char * dbpath , Oid * dbIdP , int4 * ownerIdP );
4545
4646
47-
4847/*
4948 * CREATE DATABASE
5049 */
@@ -62,7 +61,8 @@ createdb(const char *dbname, const char *dbpath, int encoding)
6261 HeapTuple tuple ;
6362 TupleDesc pg_database_dsc ;
6463 Datum new_record [Natts_pg_database ];
65- char new_record_nulls [Natts_pg_database ] = {' ' , ' ' , ' ' , ' ' };
64+ char new_record_nulls [Natts_pg_database ] = {' ' , ' ' , ' ' , ' ' , ' ' };
65+ Oid dboid ;
6666
6767 if (!get_user_info (GetUserId (), & use_super , & use_createdb ))
6868 elog (ERROR , "current user name is invalid" );
@@ -91,6 +91,8 @@ createdb(const char *dbname, const char *dbpath, int encoding)
9191 "The database path '%s' is invalid. "
9292 "This may be due to a character that is not allowed or because the chosen "
9393 "path isn't permitted for databases" , dbpath );
94+ #else
95+ locbuf [0 ] = 0 ; /* Avoid junk in strings */
9496#endif
9597
9698 /*
@@ -99,16 +101,26 @@ createdb(const char *dbname, const char *dbpath, int encoding)
99101 pg_database_rel = heap_openr (DatabaseRelationName , AccessExclusiveLock );
100102 pg_database_dsc = RelationGetDescr (pg_database_rel );
101103
104+ /*
105+ * Preassign OID for pg_database tuple, so that we know current
106+ * OID counter value
107+ */
108+ dboid = newoid ();
109+
102110 /* Form tuple */
103111 new_record [Anum_pg_database_datname - 1 ] = DirectFunctionCall1 (namein ,
104112 CStringGetDatum (dbname ));
105113 new_record [Anum_pg_database_datdba - 1 ] = Int32GetDatum (GetUserId ());
106114 new_record [Anum_pg_database_encoding - 1 ] = Int32GetDatum (encoding );
115+ new_record [Anum_pg_database_datlastsysoid - 1 ] = ObjectIdGetDatum (dboid ); /* Save current OID val */
107116 new_record [Anum_pg_database_datpath - 1 ] = DirectFunctionCall1 (textin ,
108117 CStringGetDatum (locbuf ));
109118
110119 tuple = heap_formtuple (pg_database_dsc , new_record , new_record_nulls );
111120
121+ tuple -> t_data -> t_oid = dboid ; /* override heap_insert */
122+
123+
112124 /*
113125 * Update table
114126 */
@@ -180,6 +192,7 @@ createdb(const char *dbname, const char *dbpath, int encoding)
180192 else
181193 elog (ERROR , "CREATE DATABASE: Could not initialize database directory. Delete failed as well" );
182194 }
195+
183196}
184197
185198
@@ -391,8 +404,6 @@ get_db_info(const char *name, char *dbpath, Oid *dbIdP, int4 *ownerIdP)
391404 return HeapTupleIsValid (tuple );
392405}
393406
394-
395-
396407static bool
397408get_user_info (Oid use_sysid , bool * use_super , bool * use_createdb )
398409{
0 commit comments