1 /* src/interfaces/ecpg/preproc/ecpg.addons */
2 ECPG: stmtClosePortalStmt block
6 if (pg_strcasecmp($1+strlen("close "), "database") == 0)
9 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CLOSE DATABASE statement");
11 fprintf(yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");");
18 output_statement($1, 0, ECPGst_normal);
20 ECPG: stmtDeallocateStmt block
22 output_deallocate_prepare_statement($1);
24 ECPG: stmtDeclareCursorStmt block
25 { output_simple_statement($1); }
26 ECPG: stmtDiscardStmt block
27 ECPG: stmtFetchStmt block
28 { output_statement($1, 1, ECPGst_normal); }
29 ECPG: stmtDeleteStmt block
30 ECPG: stmtInsertStmt block
31 ECPG: stmtSelectStmt block
32 ECPG: stmtUpdateStmt block
33 { output_statement($1, 1, ECPGst_prepnormal); }
34 ECPG: stmtExecuteStmt block
35 { output_statement($1, 1, ECPGst_execute); }
36 ECPG: stmtPrepareStmt block
38 if ($1.type == NULL || strlen($1.type) == 0)
39 output_prepare_statement($1.name, $1.stmt);
41 output_statement(cat_str(5, mm_strdup("prepare"), $1.name, $1.type, mm_strdup("as"), $1.stmt), 0, ECPGst_normal);
43 ECPG: stmtTransactionStmt block
45 fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
49 ECPG: stmtViewStmt rule
52 fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
59 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CONNECT statement");
61 fprintf(yyout, "{ ECPGconnect(__LINE__, %d, %s, %d); ", compat, $1, autocommit);
68 output_simple_statement($1);
72 fprintf(yyout,"ECPGdeallocate_desc(__LINE__, %s);",$1);
78 output_simple_statement($1);
82 fprintf(yyout, "{ ECPGdescribe(__LINE__, %d, %s,", compat, $1);
83 dump_variables(argsresult, 1);
84 fputs("ECPGt_EORT);", yyout);
93 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DISCONNECT statement");
95 fprintf(yyout, "{ ECPGdisconnect(__LINE__, %s);",
96 $1 ? $1 : "\"CURRENT\"");
100 | ECPGExecuteImmediateStmt { output_statement($1, 0, ECPGst_exec_immediate); }
103 const char *con = connection ? connection : "NULL";
105 if (strcmp($1, "all") == 0)
106 fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
107 else if ($1[0] == ':')
108 fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, %s);", compat, con, $1+1);
110 fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, \"%s\");", compat, con, $1);
117 lookup_descriptor($1.name, connection);
118 output_get_descr($1.name, $1.str);
122 | ECPGGetDescriptorHeader
124 lookup_descriptor($1, connection);
125 output_get_descr_header($1);
132 if ((ptr = add_additional_variables($1, true)) != NULL)
134 connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
135 output_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
141 fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
148 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in SET CONNECTION statement");
150 fprintf(yyout, "{ ECPGsetconn(__LINE__, %s);", $1);
156 lookup_descriptor($1.name, connection);
157 output_set_descr($1.name, $1.str);
161 | ECPGSetDescriptorHeader
163 lookup_descriptor($1, connection);
164 output_set_descr_header($1);
170 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in TYPE statement");
172 fprintf(yyout, "%s", $1);
174 output_line_number();
179 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in VAR statement");
181 output_simple_statement($1);
186 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER statement");
188 output_simple_statement($1);
190 ECPG: where_or_current_clauseWHERECURRENT_POFcursor_name block
192 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
193 $$ = cat_str(2,mm_strdup("where current of"), cursor_marker);
195 ECPG: CopyStmtCOPYopt_binaryqualified_nameopt_column_listopt_oidscopy_fromcopy_file_namecopy_delimiteropt_withcopy_options addon
196 if (strcmp($6, "from") == 0 &&
197 (strcmp($7, "stdin") == 0 || strcmp($7, "stdout") == 0))
198 mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
199 ECPG: var_valueNumericOnly addon
203 $1 = mm_strdup("$0");
205 ECPG: fetch_argscursor_name addon
206 add_additional_variables($1, false);
210 $1 = mm_strdup("$0");
212 ECPG: fetch_argsfrom_incursor_name addon
213 add_additional_variables($2, false);
217 $2 = mm_strdup("$0");
219 ECPG: fetch_argsNEXTopt_from_incursor_name addon
220 ECPG: fetch_argsPRIORopt_from_incursor_name addon
221 ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
222 ECPG: fetch_argsLAST_Popt_from_incursor_name addon
223 ECPG: fetch_argsALLopt_from_incursor_name addon
224 add_additional_variables($3, false);
228 $3 = mm_strdup("$0");
230 ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
231 add_additional_variables($3, false);
235 $3 = mm_strdup("$0");
240 $1 = mm_strdup("$0");
242 ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
243 ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
244 add_additional_variables($4, false);
248 $4 = mm_strdup("$0");
250 ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon
251 ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
252 ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
253 ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
254 add_additional_variables($4, false);
258 $4 = mm_strdup("$0");
263 $2 = mm_strdup("$0");
265 ECPG: cursor_namename rule
268 char *curname = mm_alloc(strlen($1) + 2);
269 sprintf(curname, ":%s", $1);
274 ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
278 $$.stmt = cat_str(3, mm_strdup("\""), $5, mm_strdup("\""));
280 | PREPARE prepared_name FROM execstring
286 ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
288 ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
290 struct cursor *ptr, *this;
291 char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : mm_strdup($2);
292 char *comment, *c1, *c2;
293 int (* strcmp_fn)(const char *, const char *) = ($2[0] == ':' ? strcmp : pg_strcasecmp);
295 for (ptr = cur; ptr != NULL; ptr = ptr->next)
297 if (strcmp_fn($2, ptr->name) == 0)
300 mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", $2+1);
302 mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", $2);
306 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
310 this->function = (current_function ? mm_strdup(current_function) : NULL);
311 this->connection = connection;
312 this->opened = false;
313 this->command = cat_str(7, mm_strdup("declare"), cursor_marker, $3, mm_strdup("cursor"), $5, mm_strdup("for"), $7);
314 this->argsinsert = argsinsert;
315 this->argsinsert_oos = NULL;
316 this->argsresult = argsresult;
317 this->argsresult_oos = NULL;
318 argsinsert = argsresult = NULL;
321 c1 = mm_strdup(this->command);
322 if ((c2 = strstr(c1, "*/")) != NULL)
324 /* We put this text into a comment, so we better remove [*][/]. */
328 comment = cat_str(3, mm_strdup("/*"), c1, mm_strdup("*/"));
330 if ((braces_open > 0) && INFORMIX_MODE) /* we're in a function */
331 $$ = cat_str(3, adjust_outofscope_cursor_vars(this),
332 mm_strdup("ECPG_informix_reset_sqlca();"),
335 $$ = cat2_str(adjust_outofscope_cursor_vars(this), comment);
337 ECPG: ClosePortalStmtCLOSEcursor_name block
339 char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : $2;
340 $$ = cat2_str(mm_strdup("close"), cursor_marker);
344 if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit)
345 $$ = mm_strdup("with hold");
349 ECPG: into_clauseINTOOptTempTableName block
352 $$= cat2_str(mm_strdup("into"), $2);
354 | ecpg_into { $$ = EMPTY; }
355 ECPG: table_refselect_with_parensopt_alias_clause addon
357 mmerror(PARSE_ERROR, ET_ERROR, "subquery in FROM must have an alias");
358 ECPG: table_refLATERAL_Pselect_with_parensopt_alias_clause addon
360 mmerror(PARSE_ERROR, ET_ERROR, "subquery in FROM must have an alias");
361 ECPG: TypenameSimpleTypenameopt_array_bounds block
362 { $$ = cat2_str($1, $2.str); }
363 ECPG: TypenameSETOFSimpleTypenameopt_array_bounds block
364 { $$ = cat_str(3, mm_strdup("setof"), $2, $3.str); }
365 ECPG: opt_array_boundsopt_array_bounds'['']' block
367 $$.index1 = $1.index1;
368 $$.index2 = $1.index2;
369 if (strcmp($$.index1, "-1") == 0)
370 $$.index1 = mm_strdup("0");
371 else if (strcmp($1.index2, "-1") == 0)
372 $$.index2 = mm_strdup("0");
373 $$.str = cat_str(2, $1.str, mm_strdup("[]"));
375 | opt_array_bounds '[' Iresult ']'
377 $$.index1 = $1.index1;
378 $$.index2 = $1.index2;
379 if (strcmp($1.index1, "-1") == 0)
380 $$.index1 = strdup($3);
381 else if (strcmp($1.index2, "-1") == 0)
382 $$.index2 = strdup($3);
383 $$.str = cat_str(4, $1.str, mm_strdup("["), $3, mm_strdup("]"));
385 ECPG: opt_array_bounds
387 $$.index1 = mm_strdup("-1");
388 $$.index2 = mm_strdup("-1");
391 ECPG: IconstICONST block
392 { $$ = make_name(); }
393 ECPG: AexprConstNULL_P rule
395 | civarind { $$ = $1; }
396 ECPG: ColIdcol_name_keyword rule
397 | ECPGKeywords { $$ = $1; }
398 | ECPGCKeywords { $$ = $1; }
399 | CHAR_P { $$ = mm_strdup("char"); }
400 | VALUES { $$ = mm_strdup("values"); }
401 ECPG: type_function_nametype_func_name_keyword rule
402 | ECPGKeywords { $$ = $1; }
403 | ECPGTypeName { $$ = $1; }
404 | ECPGCKeywords { $$ = $1; }
405 ECPG: VariableShowStmtSHOWALL block
407 mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
410 ECPG: FetchStmtMOVEfetch_args rule
411 | FETCH fetch_args ecpg_fetch_into
413 $$ = cat2_str(mm_strdup("fetch"), $2);
415 | FETCH FORWARD cursor_name opt_ecpg_fetch_into
417 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
418 add_additional_variables($3, false);
419 $$ = cat_str(2, mm_strdup("fetch forward"), cursor_marker);
421 | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
423 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
424 add_additional_variables($4, false);
425 $$ = cat_str(2, mm_strdup("fetch forward from"), cursor_marker);
427 | FETCH BACKWARD cursor_name opt_ecpg_fetch_into
429 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
430 add_additional_variables($3, false);
431 $$ = cat_str(2, mm_strdup("fetch backward"), cursor_marker);
433 | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
435 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
436 add_additional_variables($4, false);
437 $$ = cat_str(2, mm_strdup("fetch backward from"), cursor_marker);
439 | MOVE FORWARD cursor_name
441 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
442 add_additional_variables($3, false);
443 $$ = cat_str(2, mm_strdup("move forward"), cursor_marker);
445 | MOVE FORWARD from_in cursor_name
447 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
448 add_additional_variables($4, false);
449 $$ = cat_str(2, mm_strdup("move forward from"), cursor_marker);
451 | MOVE BACKWARD cursor_name
453 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
454 add_additional_variables($3, false);
455 $$ = cat_str(2, mm_strdup("move backward"), cursor_marker);
457 | MOVE BACKWARD from_in cursor_name
459 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
460 add_additional_variables($4, false);
461 $$ = cat_str(2, mm_strdup("move backward from"), cursor_marker);
463 ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
465 mmerror(PARSE_ERROR, ET_WARNING, "no longer supported LIMIT #,# syntax passed to server");
466 $$ = cat_str(4, mm_strdup("limit"), $2, mm_strdup(","), $4);
468 ECPG: SignedIconstIconst rule