9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
16
16
17
- #include < time.h>
18
-
19
17
#include " postgres.h"
20
18
19
+ #include < time.h>
20
+ #include < unistd.h>
21
21
22
22
#include " access/attnum.h"
23
23
#include " access/htup.h"
50
50
#include " utils/nabstime.h"
51
51
#include " utils/rel.h"
52
52
53
- #define DO_START { \
54
- StartTransactionCommand ();\
55
- }
56
53
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
+
62
62
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 ;
64
78
static Oid objectid;
65
79
66
80
%}
@@ -71,12 +85,14 @@ static Oid objectid;
71
85
IndexElem *ielem;
72
86
char *str;
73
87
int ival;
88
+ Oid oidval;
74
89
}
75
90
76
91
%type <list> boot_index_params
77
92
%type <ielem> boot_index_param
78
93
%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
80
96
81
97
%token <ival> CONST ID
82
98
%token OPEN XCLOSE XCREATE INSERT_TUPLE
@@ -114,42 +130,49 @@ Boot_Query :
114
130
Boot_OpenStmt :
115
131
OPEN boot_ident
116
132
{
117
- DO_START ;
133
+ do_start () ;
118
134
boot_openrel (LexIDStr($2 ));
119
- DO_END ;
135
+ do_end () ;
120
136
}
121
137
;
122
138
123
139
Boot_CloseStmt :
124
140
XCLOSE boot_ident %prec low
125
141
{
126
- DO_START ;
142
+ do_start () ;
127
143
closerel (LexIDStr($2 ));
128
- DO_END ;
144
+ do_end () ;
129
145
}
130
146
| XCLOSE %prec high
131
147
{
132
- DO_START ;
148
+ do_start () ;
133
149
closerel (NULL );
134
- DO_END ;
150
+ do_end () ;
135
151
}
136
152
;
137
153
138
154
Boot_CreateStmt :
139
155
XCREATE optbootstrap boot_ident LPAREN
140
156
{
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
+ }
143
168
}
144
169
boot_typelist
145
170
{
146
- if (!Quiet)
147
- putchar (' \n ' );
148
- DO_END;
171
+ do_end ();
149
172
}
150
173
RPAREN
151
174
{
152
- DO_START ;
175
+ do_start () ;
153
176
154
177
if ($2 )
155
178
{
@@ -158,17 +181,15 @@ Boot_CreateStmt:
158
181
159
182
if (reldesc)
160
183
{
161
- puts (" create bootstrap: Warning, open relation" );
162
- puts (" exists, closing first" );
184
+ elog (DEBUG, " create bootstrap: warning, open relation exists, closing first" );
163
185
closerel (NULL );
164
186
}
165
- if (DebugMode)
166
- puts (" creating bootstrap relation" );
187
+
167
188
tupdesc = CreateTupleDesc (numattr,attrtypes);
168
189
reldesc = heap_create (LexIDStr ($3 ), tupdesc,
169
190
false , true , true );
170
191
if (DebugMode)
171
- puts ( " bootstrap relation created ok " );
192
+ elog (DEBUG, " bootstrap relation created" );
172
193
}
173
194
else
174
195
{
@@ -181,70 +202,65 @@ Boot_CreateStmt:
181
202
RELKIND_RELATION,
182
203
false ,
183
204
true );
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);
187
207
}
188
- DO_END;
189
- if (DebugMode)
190
- puts(" Commit End" );
208
+ do_end ();
191
209
}
192
210
;
193
211
194
212
Boot_InsertStmt:
195
213
INSERT_TUPLE optoideq
196
214
{
197
- DO_START ;
215
+ do_start () ;
198
216
if (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 ;
201
224
}
202
225
LPAREN boot_tuplelist RPAREN
203
226
{
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);
206
230
if (reldesc == (Relation)NULL )
207
231
{
208
- elog (ERROR," must OPEN RELATION before INSERT \n " );
232
+ elog (ERROR, " relation not open " );
209
233
err_out ();
210
234
}
211
- if (DebugMode)
212
- puts (" Insert Begin" );
213
235
objectid = $2 ;
214
236
InsertOneTuple (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 ();
222
238
}
223
239
;
224
240
225
241
Boot_DeclareIndexStmt:
226
242
XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
227
243
{
228
- DO_START ;
244
+ do_start () ;
229
245
230
246
DefineIndex (LexIDStr ($5 ),
231
247
LexIDStr ($3 ),
232
248
LexIDStr ($7 ),
233
249
$9 , NIL, 0 , 0 , 0 , NIL);
234
- DO_END ;
250
+ do_end () ;
235
251
}
236
252
;
237
253
238
254
Boot_DeclareUniqueIndexStmt:
239
255
XDECLARE UNIQUE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
240
256
{
241
- DO_START ;
257
+ do_start () ;
242
258
243
259
DefineIndex (LexIDStr ($6 ),
244
260
LexIDStr ($4 ),
245
261
LexIDStr ($8 ),
246
262
$10 , NIL, 1 , 0 , 0 , NIL);
247
- DO_END ;
263
+ do_end () ;
248
264
}
249
265
;
250
266
@@ -280,10 +296,8 @@ boot_type_thing:
280
296
boot_ident EQUALS boot_ident
281
297
{
282
298
if (++numattr > MAXATTR)
283
- elog (FATAL," Too many attributes \n " );
299
+ elog (FATAL, " too many columns " );
284
300
DefineAttr (LexIDStr ($1 ),LexIDStr ($3 ),numattr-1 );
285
- if (DebugMode)
286
- printf (" \n " );
287
301
}
288
302
;
289
303
@@ -299,10 +313,10 @@ boot_tuplelist:
299
313
;
300
314
301
315
boot_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 ++); }
304
318
| NULLVAL
305
- { InsertOneNull(num_tuples_read ++); }
319
+ { InsertOneNull (num_columns_read ++); }
306
320
;
307
321
308
322
boot_const :
0 commit comments