OSDN Git Service

de46f51ca721d59b277f734ce20d2ad3cc1d1677
[pg-rex/syncrep.git] / src / interfaces / ecpg / preproc / ecpg.addons
1 /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.16 2010/01/29 16:28:13 meskes Exp $ */
2 ECPG: stmtClosePortalStmt block
3         {
4                 if (INFORMIX_MODE)
5                 {
6                         if (pg_strcasecmp($1+strlen("close "), "database") == 0)
7                         {
8                                 if (connection)
9                                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CLOSE DATABASE statement");
10
11                                 fprintf(yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");");
12                                 whenever_action(2);
13                                 free($1);
14                                 break;
15                         }
16                 }
17
18                 output_statement($1, 0, ECPGst_normal);
19         }
20 ECPG: stmtDeallocateStmt block
21         {
22                 if (connection)
23                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DEALLOCATE statement");
24
25                 output_deallocate_prepare_statement($1);
26         }
27 ECPG: stmtDeclareCursorStmt block
28         { output_simple_statement($1); }
29 ECPG: stmtDiscardStmt block
30 ECPG: stmtFetchStmt block
31         { output_statement($1, 1, ECPGst_normal); }
32 ECPG: stmtDeleteStmt block
33 ECPG: stmtInsertStmt block
34 ECPG: stmtSelectStmt block
35 ECPG: stmtUpdateStmt block
36         { output_statement($1, 1, ECPGst_prepnormal); }
37 ECPG: stmtExecuteStmt block
38         { output_statement($1, 1, ECPGst_execute); }
39 ECPG: stmtPrepareStmt block
40         {
41                 if ($1.type == NULL || strlen($1.type) == 0)
42                         output_prepare_statement($1.name, $1.stmt);
43                 else    
44                         output_statement(cat_str(5, make_str("prepare"), $1.name, $1.type, make_str("as"), $1.stmt), 0, ECPGst_normal);
45         }
46 ECPG: stmtTransactionStmt block
47         {
48                 fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
49                 whenever_action(2);
50                 free($1);
51         }
52 ECPG: stmtViewStmt rule
53         | ECPGAllocateDescr
54         {
55                 fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
56                 whenever_action(0);
57                 free($1);
58         }
59         | ECPGConnect
60         {
61                 if (connection)
62                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CONNECT statement");
63
64                 fprintf(yyout, "{ ECPGconnect(__LINE__, %d, %s, %d); ", compat, $1, autocommit);
65                 reset_variables();
66                 whenever_action(2);
67                 free($1);
68         }
69         | ECPGCursorStmt
70         {
71                 output_simple_statement($1);
72         }
73         | ECPGDeallocateDescr
74         {
75                 if (connection)
76                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DEALLOCATE statement");
77                 fprintf(yyout,"ECPGdeallocate_desc(__LINE__, %s);",$1);
78                 whenever_action(0);
79                 free($1);
80         }
81         | ECPGDeclare
82         {
83                 output_simple_statement($1);
84         }
85         | ECPGDescribe
86         {
87                 fprintf(yyout, "{ ECPGdescribe(__LINE__, %d, %s,", compat, $1);
88                 dump_variables(argsresult, 1);
89                 fputs("ECPGt_EORT);", yyout);
90                 fprintf(yyout, "}");
91                 output_line_number();
92
93                 free($1);
94         }
95         | ECPGDisconnect
96         {
97                 if (connection)
98                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DISCONNECT statement");
99
100                 fprintf(yyout, "{ ECPGdisconnect(__LINE__, %s);",
101                                 $1 ? $1 : "\"CURRENT\"");
102                 whenever_action(2);
103                 free($1);
104         }
105         | ECPGExecuteImmediateStmt      { output_statement($1, 0, ECPGst_exec_immediate); }
106         | ECPGFree
107         {
108                 const char *con = connection ? connection : "NULL";
109                 if (strcmp($1, "all"))
110                         fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, \"%s\");", compat, con, $1);
111                 else
112                         fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
113
114                 whenever_action(2);
115                 free($1);
116         }
117         | ECPGGetDescriptor
118         {
119                 lookup_descriptor($1.name, connection);
120                 output_get_descr($1.name, $1.str);
121                 free($1.name);
122                 free($1.str);
123         }
124         | ECPGGetDescriptorHeader
125         {
126                 lookup_descriptor($1, connection);
127                 output_get_descr_header($1);
128                 free($1);
129         }
130         | ECPGOpen
131         {
132                 struct cursor *ptr;
133
134                 if ((ptr = add_additional_variables($1, true)) != NULL)
135                 {
136                         connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
137                         output_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
138                         ptr->opened = true;
139                 }
140         }
141         | ECPGSetAutocommit
142         {
143                 fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
144                 whenever_action(2);
145                 free($1);
146         }
147         | ECPGSetConnection
148         {
149                 if (connection)
150                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in SET CONNECTION statement");
151
152                 fprintf(yyout, "{ ECPGsetconn(__LINE__, %s);", $1);
153                 whenever_action(2);
154                 free($1);
155         }
156         | ECPGSetDescriptor
157         {
158                 lookup_descriptor($1.name, connection);
159                 output_set_descr($1.name, $1.str);
160                 free($1.name);
161                 free($1.str);
162         }
163         | ECPGSetDescriptorHeader
164         {
165                 lookup_descriptor($1, connection);
166                 output_set_descr_header($1);
167                 free($1);
168         }
169         | ECPGTypedef
170         {
171                 if (connection)
172                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in TYPE statement");
173
174                 fprintf(yyout, "%s", $1);
175                 free($1);
176                 output_line_number();
177         }
178         | ECPGVar
179         {
180                 if (connection)
181                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in VAR statement");
182
183                 output_simple_statement($1);
184         }
185         | ECPGWhenever
186         {
187                 if (connection)
188                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER statement");
189
190                 output_simple_statement($1);
191         }
192 ECPG: CopyStmtCOPYopt_binaryqualified_nameopt_column_listopt_oidscopy_fromcopy_file_namecopy_delimiteropt_withcopy_options addon
193                         if (strcmp($6, "to") == 0 && strcmp($7, "stdin") == 0)
194                                 mmerror(PARSE_ERROR, ET_ERROR, "COPY TO STDIN is not possible");
195                         else if (strcmp($6, "from") == 0 && strcmp($7, "stdout") == 0)
196                                 mmerror(PARSE_ERROR, ET_ERROR, "COPY FROM STDOUT is not possible");
197                         else if (strcmp($6, "from") == 0 && strcmp($7, "stdin") == 0)
198                                 mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
199 ECPG: CopyStmtCOPYselect_with_parensTOcopy_file_nameopt_withcopy_options addon
200                         if (strcmp($4, "stdin") == 0)
201                                 mmerror(PARSE_ERROR, ET_ERROR, "COPY TO STDIN is not possible");
202 ECPG: ConstraintAttributeSpecConstraintDeferrabilitySpecConstraintTimeSpec addon
203                         if (strcmp($1, "deferrable") != 0 && strcmp($2, "initially deferrable") == 0 )
204                                 mmerror(PARSE_ERROR, ET_ERROR, "constraint declared INITIALLY DEFERRED must be DEFERRABLE");
205 ECPG: ConstraintAttributeSpecConstraintTimeSpecConstraintDeferrabilitySpec addon
206                         if (strcmp($2, "deferrable") != 0 && strcmp($1, "initially deferrable") == 0 )
207                                 mmerror(PARSE_ERROR, ET_ERROR, "constraint declared INITIALLY DEFERRED must be DEFERRABLE");
208 ECPG: var_valueNumericOnly addon
209                 if ($1[0] == '$')
210                 {
211                         free($1);
212                         $1 = make_str("$0");
213                 }
214 ECPG: fetch_argscursor_name addon
215                 add_additional_variables($1, false);
216                 if ($1[0] == ':')
217                 {
218                         free($1);
219                         $1 = make_str("$0");
220                 }
221 ECPG: fetch_argsfrom_incursor_name addon
222                 add_additional_variables($2, false);
223                 if ($2[0] == ':')
224                 {
225                         free($2);
226                         $2 = make_str("$0");
227                 }
228 ECPG: fetch_argsNEXTopt_from_incursor_name addon
229 ECPG: fetch_argsPRIORopt_from_incursor_name addon
230 ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
231 ECPG: fetch_argsLAST_Popt_from_incursor_name addon
232 ECPG: fetch_argsALLopt_from_incursor_name addon
233                 add_additional_variables($3, false);
234                 if ($3[0] == ':')
235                 {
236                         free($3);
237                         $3 = make_str("$0");
238                 }
239 ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
240                 add_additional_variables($3, false);
241                 if ($3[0] == ':')
242                 {
243                         free($3);
244                         $3 = make_str("$0");
245                 }
246                 if ($1[0] == '$')
247                 {
248                         free($1);
249                         $1 = make_str("$0");
250                 }
251 ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
252 ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
253                 add_additional_variables($4, false);
254                 if ($4[0] == ':')
255                 {
256                         free($4);
257                         $4 = make_str("$0");
258                 }
259 ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon
260 ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
261 ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
262 ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
263                 add_additional_variables($4, false);
264                 if ($4[0] == ':')
265                 {
266                         free($4);
267                         $4 = make_str("$0");
268                 }
269                 if ($2[0] == '$')
270                 {
271                         free($2);
272                         $2 = make_str("$0");
273                 }
274 ECPG: cursor_namename rule
275         | char_civar
276                 {
277                         char *curname = mm_alloc(strlen($1) + 2);
278                         sprintf(curname, ":%s", $1);
279                         free($1);
280                         $1 = curname;
281                         $$ = $1;
282                 }
283 ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
284         {
285                 $$.name = $2;
286                 $$.type = $3;
287                 $$.stmt = cat_str(3, make_str("\""), $5, make_str("\""));
288         }
289         | PREPARE prepared_name FROM execstring
290         {
291                 $$.name = $2;
292                 $$.type = NULL;
293                 $$.stmt = $4;
294         }
295 ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
296         { $$ = $2; }
297 ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
298         {
299                 struct cursor *ptr, *this;
300                 char *cursor_marker = $2[0] == ':' ? make_str("$0") : mm_strdup($2);
301                 char *comment, *c1, *c2;
302
303                 for (ptr = cur; ptr != NULL; ptr = ptr->next)
304                 {
305                         if (strcmp($2, ptr->name) == 0)
306                                 mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", $2);
307                 }
308
309                 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
310
311                 this->next = cur;
312                 this->name = $2;
313                 this->function = (current_function ? mm_strdup(current_function) : NULL);
314                 this->connection = connection;
315                 this->opened = false;
316                 this->command =  cat_str(7, make_str("declare"), cursor_marker, $3, make_str("cursor"), $5, make_str("for"), $7);
317                 this->argsinsert = argsinsert;
318                 this->argsinsert_oos = NULL;
319                 this->argsresult = argsresult;
320                 this->argsresult_oos = NULL;
321                 argsinsert = argsresult = NULL;
322                 cur = this;
323
324                 c1 = mm_strdup(this->command);
325                 if ((c2 = strstr(c1, "*/")) != NULL)
326                 {
327                         /* We put this text into a comment, so we better remove [*][/]. */
328                         c2[0] = '.';
329                         c2[1] = '.';
330                 }
331                 comment = cat_str(3, make_str("/*"), c1, make_str("*/"));
332
333                 if ((braces_open > 0) && INFORMIX_MODE) /* we're in a function */
334                         $$ = cat_str(3, adjust_outofscope_cursor_vars(this),
335                                 make_str("ECPG_informix_reset_sqlca();"),
336                                 comment);
337                 else
338                         $$ = cat2_str(adjust_outofscope_cursor_vars(this), comment);
339         }
340 ECPG: ClosePortalStmtCLOSEcursor_name block
341         {
342                 char *cursor_marker = $2[0] == ':' ? make_str("$0") : $2;
343                 $$ = cat2_str(make_str("close"), cursor_marker);
344         }
345 ECPG: opt_hold block
346         {
347                 if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit == true)
348                         $$ = make_str("with hold");
349                 else
350                         $$ = EMPTY;
351         }
352 ECPG: into_clauseINTOOptTempTableName block
353                                         {
354                                                 FoundInto = 1;
355                                                 $$= cat2_str(make_str("into"), $2);
356                                         }
357         | ecpg_into                     { $$ = EMPTY; }
358 ECPG: table_refselect_with_parens addon
359                 mmerror(PARSE_ERROR, ET_ERROR, "subquery in FROM must have an alias");
360 ECPG: TypenameSimpleTypenameopt_array_bounds block
361         {       $$ = cat2_str($1, $2.str); }
362 ECPG: TypenameSETOFSimpleTypenameopt_array_bounds block
363         {       $$ = $$ = cat_str(3, make_str("setof"), $2, $3.str); }
364 ECPG: opt_array_boundsopt_array_bounds'['']' block
365         {
366                 $$.index1 = $1.index1;
367                 $$.index2 = $1.index2;
368                 if (strcmp($$.index1, "-1") == 0)
369                         $$.index1 = make_str("0");
370                 else if (strcmp($1.index2, "-1") == 0)
371                         $$.index2 = make_str("0");
372                 $$.str = cat_str(2, $1.str, make_str("[]"));
373         }
374         | opt_array_bounds '[' Iresult ']'
375         {
376                 $$.index1 = $1.index1;
377                 $$.index2 = $1.index2;
378                 if (strcmp($1.index1, "-1") == 0)
379                         $$.index1 = strdup($3);
380                 else if (strcmp($1.index2, "-1") == 0)
381                         $$.index2 = strdup($3);
382                 $$.str = cat_str(4, $1.str, make_str("["), $3, make_str("]"));
383         }
384 ECPG: opt_array_bounds
385         {
386                 $$.index1 = make_str("-1");
387                 $$.index2 = make_str("-1");
388                 $$.str= EMPTY;
389         }
390 ECPG: IconstICONST block
391         { $$ = make_name(); }
392 ECPG: AexprConstNULL_P rule
393         | civar                 { $$ = $1; }
394         | civarind              { $$ = $1; }
395 ECPG: ColIdcol_name_keyword rule
396         | ECPGKeywords                  { $$ = $1; }
397         | ECPGCKeywords                 { $$ = $1; }
398         | CHAR_P                        { $$ = make_str("char"); }
399         | VALUES                        { $$ = make_str("values"); }
400 ECPG: type_function_nametype_func_name_keyword rule
401         | ECPGKeywords                          { $$ = $1; }
402         | ECPGTypeName                          { $$ = $1; }
403         | ECPGCKeywords                         { $$ = $1; }
404 ECPG: VariableShowStmtSHOWALL block
405         {
406                 mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
407                 $$ = EMPTY;
408         }
409 ECPG: FetchStmtMOVEfetch_args rule
410         | FETCH fetch_args ecpg_fetch_into
411         {
412                 $$ = cat2_str(make_str("fetch"), $2);
413         }
414         | FETCH FORWARD cursor_name opt_ecpg_fetch_into
415         {
416                 char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
417                 add_additional_variables($3, false);
418                 $$ = cat_str(2, make_str("fetch forward"), cursor_marker);
419         }
420         | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
421         {
422                 char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
423                 add_additional_variables($4, false);
424                 $$ = cat_str(2, make_str("fetch forward from"), cursor_marker);
425         }
426         | FETCH BACKWARD cursor_name opt_ecpg_fetch_into
427         {
428                 char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
429                 add_additional_variables($3, false);
430                 $$ = cat_str(2, make_str("fetch backward"), cursor_marker);
431         }
432         | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
433         {
434                 char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
435                 add_additional_variables($4, false);
436                 $$ = cat_str(2, make_str("fetch backward from"), cursor_marker);
437         }
438         | MOVE FORWARD cursor_name
439         {
440                 char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
441                 add_additional_variables($3, false);
442                 $$ = cat_str(2, make_str("move forward"), cursor_marker);
443         }
444         | MOVE FORWARD from_in cursor_name
445         {
446                 char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
447                 add_additional_variables($4, false);
448                 $$ = cat_str(2, make_str("move forward from"), cursor_marker);
449         }
450         | MOVE BACKWARD cursor_name
451         {
452                 char *cursor_marker = $3[0] == ':' ? make_str("$0") : $3;
453                 add_additional_variables($3, false);
454                 $$ = cat_str(2, make_str("move backward"), cursor_marker);
455         }
456         | MOVE BACKWARD from_in cursor_name
457         {
458                 char *cursor_marker = $4[0] == ':' ? make_str("$0") : $4;
459                 add_additional_variables($4, false);
460                 $$ = cat_str(2, make_str("move backward from"), cursor_marker);
461         }
462 ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
463         {
464                 mmerror(PARSE_ERROR, ET_WARNING, "no longer supported LIMIT #,# syntax passed to server");
465                 $$ = cat_str(4, make_str("limit"), $2, make_str(","), $4);
466         }
467 ECPG: SignedIconstIconst rule
468         | civar { $$ = $1; }