1 /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.16 2010/01/29 16:28:13 meskes Exp $ */
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
23 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DEALLOCATE statement");
25 output_deallocate_prepare_statement($1);
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
41 if ($1.type == NULL || strlen($1.type) == 0)
42 output_prepare_statement($1.name, $1.stmt);
44 output_statement(cat_str(5, make_str("prepare"), $1.name, $1.type, make_str("as"), $1.stmt), 0, ECPGst_normal);
46 ECPG: stmtTransactionStmt block
48 fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
52 ECPG: stmtViewStmt rule
55 fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
62 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CONNECT statement");
64 fprintf(yyout, "{ ECPGconnect(__LINE__, %d, %s, %d); ", compat, $1, autocommit);
71 output_simple_statement($1);
76 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DEALLOCATE statement");
77 fprintf(yyout,"ECPGdeallocate_desc(__LINE__, %s);",$1);
83 output_simple_statement($1);
87 fprintf(yyout, "{ ECPGdescribe(__LINE__, %d, %s,", compat, $1);
88 dump_variables(argsresult, 1);
89 fputs("ECPGt_EORT);", yyout);
98 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DISCONNECT statement");
100 fprintf(yyout, "{ ECPGdisconnect(__LINE__, %s);",
101 $1 ? $1 : "\"CURRENT\"");
105 | ECPGExecuteImmediateStmt { output_statement($1, 0, ECPGst_exec_immediate); }
108 const char *con = connection ? connection : "NULL";
109 if (strcmp($1, "all"))
110 fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, \"%s\");", compat, con, $1);
112 fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
119 lookup_descriptor($1.name, connection);
120 output_get_descr($1.name, $1.str);
124 | ECPGGetDescriptorHeader
126 lookup_descriptor($1, connection);
127 output_get_descr_header($1);
134 if ((ptr = add_additional_variables($1, true)) != NULL)
136 connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
137 output_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
143 fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
150 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in SET CONNECTION statement");
152 fprintf(yyout, "{ ECPGsetconn(__LINE__, %s);", $1);
158 lookup_descriptor($1.name, connection);
159 output_set_descr($1.name, $1.str);
163 | ECPGSetDescriptorHeader
165 lookup_descriptor($1, connection);
166 output_set_descr_header($1);
172 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in TYPE statement");
174 fprintf(yyout, "%s", $1);
176 output_line_number();
181 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in VAR statement");
183 output_simple_statement($1);
188 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER statement");
190 output_simple_statement($1);
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
214 ECPG: fetch_argscursor_name addon
215 add_additional_variables($1, false);
221 ECPG: fetch_argsfrom_incursor_name addon
222 add_additional_variables($2, false);
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);
239 ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
240 add_additional_variables($3, false);
251 ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
252 ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
253 add_additional_variables($4, false);
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);
274 ECPG: cursor_namename rule
277 char *curname = mm_alloc(strlen($1) + 2);
278 sprintf(curname, ":%s", $1);
283 ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
287 $$.stmt = cat_str(3, make_str("\""), $5, make_str("\""));
289 | PREPARE prepared_name FROM execstring
295 ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
297 ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
299 struct cursor *ptr, *this;
300 char *cursor_marker = $2[0] == ':' ? make_str("$0") : mm_strdup($2);
301 char *comment, *c1, *c2;
303 for (ptr = cur; ptr != NULL; ptr = ptr->next)
305 if (strcmp($2, ptr->name) == 0)
306 mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", $2);
309 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
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;
324 c1 = mm_strdup(this->command);
325 if ((c2 = strstr(c1, "*/")) != NULL)
327 /* We put this text into a comment, so we better remove [*][/]. */
331 comment = cat_str(3, make_str("/*"), c1, make_str("*/"));
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();"),
338 $$ = cat2_str(adjust_outofscope_cursor_vars(this), comment);
340 ECPG: ClosePortalStmtCLOSEcursor_name block
342 char *cursor_marker = $2[0] == ':' ? make_str("$0") : $2;
343 $$ = cat2_str(make_str("close"), cursor_marker);
347 if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit == true)
348 $$ = make_str("with hold");
352 ECPG: into_clauseINTOOptTempTableName block
355 $$= cat2_str(make_str("into"), $2);
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
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("[]"));
374 | opt_array_bounds '[' Iresult ']'
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("]"));
384 ECPG: opt_array_bounds
386 $$.index1 = make_str("-1");
387 $$.index2 = make_str("-1");
390 ECPG: IconstICONST block
391 { $$ = make_name(); }
392 ECPG: AexprConstNULL_P rule
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
406 mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
409 ECPG: FetchStmtMOVEfetch_args rule
410 | FETCH fetch_args ecpg_fetch_into
412 $$ = cat2_str(make_str("fetch"), $2);
414 | FETCH FORWARD cursor_name opt_ecpg_fetch_into
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);
420 | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
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);
426 | FETCH BACKWARD cursor_name opt_ecpg_fetch_into
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);
432 | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
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);
438 | MOVE FORWARD cursor_name
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);
444 | MOVE FORWARD from_in cursor_name
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);
450 | MOVE BACKWARD cursor_name
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);
456 | MOVE BACKWARD from_in cursor_name
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);
462 ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
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);
467 ECPG: SignedIconstIconst rule