99 *
1010 *
1111 * IDENTIFICATION
12- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.35 2001/01/24 19:42:51 momjian Exp $
12+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.36 2001/05/12 01:48:49 petere Exp $
1313 *
1414 *-------------------------------------------------------------------------
1515*/
1616
17- #include < time.h>
18-
1917#include " postgres.h"
2018
19+ #include < time.h>
20+ #include < unistd.h>
2121
2222#include " access/attnum.h"
2323#include " access/htup.h"
5050#include " utils/nabstime.h"
5151#include " utils/rel.h"
5252
53- #define DO_START { \
54- StartTransactionCommand ();\
55- }
5653
57- #define DO_END { \
58- CommitTransactionCommand ();\
59- if (!Quiet) { EMITPROMPT; }\
60- fflush (stdout); \
61- }
54+ static void
55+ do_start ()
56+ {
57+ StartTransactionCommand ();
58+ if (DebugMode)
59+ elog (DEBUG," start transaction" );
60+ }
61+
6262
63- int num_tuples_read =0 ;
63+ static void
64+ do_end ()
65+ {
66+ CommitTransactionCommand ();
67+ if (DebugMode)
68+ elog (DEBUG," commit transaction" );
69+ if (isatty (0 ))
70+ {
71+ printf (" bootstrap>" );
72+ fflush (stdout);
73+ }
74+ }
75+
76+
77+ int num_columns_read =0 ;
6478static Oid objectid;
6579
6680%}
@@ -71,12 +85,14 @@ static Oid objectid;
7185IndexElem*ielem;
7286char *str;
7387int ival;
88+ Oidoidval;
7489}
7590
7691%type <list> boot_index_params
7792%type <ielem> boot_index_param
7893%type <ival> boot_const boot_ident
79- %type <ival> optbootstrap optoideq boot_tuple boot_tuplelist
94+ %type <ival> optbootstrap boot_tuple boot_tuplelist
95+ %type <oidval> optoideq
8096
8197%token <ival> CONST ID
8298%token OPEN XCLOSE XCREATE INSERT_TUPLE
@@ -114,42 +130,49 @@ Boot_Query :
114130Boot_OpenStmt :
115131OPEN boot_ident
116132{
117- DO_START ;
133+ do_start () ;
118134boot_openrel (LexIDStr($2 ));
119- DO_END ;
135+ do_end () ;
120136}
121137;
122138
123139Boot_CloseStmt :
124140XCLOSE boot_ident %prec low
125141{
126- DO_START ;
142+ do_start () ;
127143closerel (LexIDStr($2 ));
128- DO_END ;
144+ do_end () ;
129145}
130146| XCLOSE %prec high
131147{
132- DO_START ;
148+ do_start () ;
133149closerel (NULL );
134- DO_END ;
150+ do_end () ;
135151}
136152;
137153
138154Boot_CreateStmt :
139155XCREATE optbootstrap boot_ident LPAREN
140156{
141- DO_START;
142- numattr=(int )0 ;
157+ do_start ();
158+ numattr =0 ;
159+ if (DebugMode)
160+ {
161+ if ($2 )
162+ elog (DEBUG," creating bootstrap relation %s..." ,
163+ LexIDStr ($3 ));
164+ else
165+ elog (DEBUG," creating relation %s..." ,
166+ LexIDStr ($3 ));
167+ }
143168}
144169 boot_typelist
145170{
146- if (!Quiet)
147- putchar (' \n ' );
148- DO_END;
171+ do_end ();
149172}
150173 RPAREN
151174{
152- DO_START ;
175+ do_start () ;
153176
154177if ($2 )
155178{
@@ -158,17 +181,15 @@ Boot_CreateStmt:
158181
159182if (reldesc)
160183{
161- puts (" create bootstrap: Warning, open relation" );
162- puts (" exists, closing first" );
184+ elog (DEBUG," create bootstrap: warning, open relation exists, closing first" );
163185closerel (NULL );
164186}
165- if (DebugMode)
166- puts (" creating bootstrap relation" );
187+
167188tupdesc =CreateTupleDesc (numattr,attrtypes);
168189reldesc =heap_create (LexIDStr ($3 ), tupdesc,
169190false ,true ,true );
170191if (DebugMode)
171- puts ( " bootstrap relation created ok " );
192+ elog (DEBUG, " bootstrap relation created" );
172193}
173194else
174195{
@@ -181,70 +202,65 @@ Boot_CreateStmt:
181202 RELKIND_RELATION,
182203false ,
183204true );
184- if (!Quiet)
185- printf (" CREATED relation %s with OID %u\n " ,
186- LexIDStr ($3 ), id);
205+ if (DebugMode)
206+ elog (DEBUG," relation created with oid %u" , id);
187207}
188- DO_END;
189- if (DebugMode)
190- puts(" Commit End" );
208+ do_end ();
191209}
192210;
193211
194212Boot_InsertStmt:
195213 INSERT_TUPLE optoideq
196214{
197- DO_START ;
215+ do_start () ;
198216if (DebugMode)
199- printf (" tuple %d<" , $2 );
200- num_tuples_read =0 ;
217+ {
218+ if ($2 )
219+ elog (DEBUG," inserting row with oid %u..." , $2 );
220+ else
221+ elog (DEBUG," inserting row..." );
222+ }
223+ num_columns_read =0 ;
201224}
202225 LPAREN boot_tuplelist RPAREN
203226{
204- if (num_tuples_read != numattr)
205- elog (ERROR," incorrect number of values for tuple" );
227+ if (num_columns_read != numattr)
228+ elog (ERROR," incorrect number of columns in row (expected %d, got %d)" ,
229+ numattr, num_columns_read);
206230if (reldesc == (Relation)NULL )
207231{
208- elog (ERROR," must OPEN RELATION before INSERT \n " );
232+ elog (ERROR," relation not open " );
209233err_out ();
210234}
211- if (DebugMode)
212- puts (" Insert Begin" );
213235objectid = $2 ;
214236InsertOneTuple (objectid);
215- if (DebugMode)
216- puts (" Insert End" );
217- if (!Quiet)
218- putchar (' \n ' );
219- DO_END;
220- if (DebugMode)
221- puts (" Transaction End" );
237+ do_end ();
222238}
223239;
224240
225241Boot_DeclareIndexStmt:
226242 XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
227243{
228- DO_START ;
244+ do_start () ;
229245
230246DefineIndex (LexIDStr ($5 ),
231247LexIDStr ($3 ),
232248LexIDStr ($7 ),
233249$9 , NIL,0 ,0 ,0 , NIL);
234- DO_END ;
250+ do_end () ;
235251}
236252;
237253
238254Boot_DeclareUniqueIndexStmt:
239255 XDECLARE UNIQUE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
240256{
241- DO_START ;
257+ do_start () ;
242258
243259DefineIndex (LexIDStr ($6 ),
244260LexIDStr ($4 ),
245261LexIDStr ($8 ),
246262$10 , NIL,1 ,0 ,0 , NIL);
247- DO_END ;
263+ do_end () ;
248264}
249265;
250266
@@ -280,10 +296,8 @@ boot_type_thing:
280296 boot_ident EQUALS boot_ident
281297{
282298if (++numattr > MAXATTR)
283- elog (FATAL," Too manyattributes \n " );
299+ elog (FATAL," too manycolumns " );
284300DefineAttr (LexIDStr ($1 ),LexIDStr ($3 ),numattr-1 );
285- if (DebugMode)
286- printf (" \n " );
287301}
288302;
289303
@@ -299,10 +313,10 @@ boot_tuplelist:
299313;
300314
301315boot_tuple:
302- boot_ident {InsertOneValue(objectid, LexIDStr($1 ),num_tuples_read ++); }
303- | boot_const {InsertOneValue(objectid, LexIDStr($1 ),num_tuples_read ++); }
316+ boot_ident {InsertOneValue (objectid,LexIDStr ($1 ),num_columns_read ++); }
317+ | boot_const {InsertOneValue (objectid,LexIDStr ($1 ),num_columns_read ++); }
304318| NULLVAL
305- { InsertOneNull(num_tuples_read ++); }
319+ {InsertOneNull (num_columns_read ++); }
306320;
307321
308322boot_const :