]> granicus.if.org Git - postgresql/blob - src/interfaces/ecpg/preproc/ecpg.addons
Remove the check for COPY TO STDIN and COPY FROM STDOUT from ecpg.
[postgresql] / src / interfaces / ecpg / preproc / ecpg.addons
1 /* src/interfaces/ecpg/preproc/ecpg.addons */
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                 output_deallocate_prepare_statement($1);
23         }
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
37         {
38                 if ($1.type == NULL || strlen($1.type) == 0)
39                         output_prepare_statement($1.name, $1.stmt);
40                 else
41                         output_statement(cat_str(5, mm_strdup("prepare"), $1.name, $1.type, mm_strdup("as"), $1.stmt), 0, ECPGst_normal);
42         }
43 ECPG: stmtTransactionStmt block
44         {
45                 fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
46                 whenever_action(2);
47                 free($1);
48         }
49 ECPG: stmtViewStmt rule
50         | ECPGAllocateDescr
51         {
52                 fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
53                 whenever_action(0);
54                 free($1);
55         }
56         | ECPGConnect
57         {
58                 if (connection)
59                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CONNECT statement");
60
61                 fprintf(yyout, "{ ECPGconnect(__LINE__, %d, %s, %d); ", compat, $1, autocommit);
62                 reset_variables();
63                 whenever_action(2);
64                 free($1);
65         }
66         | ECPGCursorStmt
67         {
68                 output_simple_statement($1);
69         }
70         | ECPGDeallocateDescr
71         {
72                 fprintf(yyout,"ECPGdeallocate_desc(__LINE__, %s);",$1);
73                 whenever_action(0);
74                 free($1);
75         }
76         | ECPGDeclare
77         {
78                 output_simple_statement($1);
79         }
80         | ECPGDescribe
81         {
82                 fprintf(yyout, "{ ECPGdescribe(__LINE__, %d, %s,", compat, $1);
83                 dump_variables(argsresult, 1);
84                 fputs("ECPGt_EORT);", yyout);
85                 fprintf(yyout, "}");
86                 output_line_number();
87
88                 free($1);
89         }
90         | ECPGDisconnect
91         {
92                 if (connection)
93                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DISCONNECT statement");
94
95                 fprintf(yyout, "{ ECPGdisconnect(__LINE__, %s);",
96                                 $1 ? $1 : "\"CURRENT\"");
97                 whenever_action(2);
98                 free($1);
99         }
100         | ECPGExecuteImmediateStmt      { output_statement($1, 0, ECPGst_exec_immediate); }
101         | ECPGFree
102         {
103                 const char *con = connection ? connection : "NULL";
104
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);
109                 else
110                         fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s, \"%s\");", compat, con, $1);
111
112                 whenever_action(2);
113                 free($1);
114         }
115         | ECPGGetDescriptor
116         {
117                 lookup_descriptor($1.name, connection);
118                 output_get_descr($1.name, $1.str);
119                 free($1.name);
120                 free($1.str);
121         }
122         | ECPGGetDescriptorHeader
123         {
124                 lookup_descriptor($1, connection);
125                 output_get_descr_header($1);
126                 free($1);
127         }
128         | ECPGOpen
129         {
130                 struct cursor *ptr;
131
132                 if ((ptr = add_additional_variables($1, true)) != NULL)
133                 {
134                         connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
135                         output_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
136                         ptr->opened = true;
137                 }
138         }
139         | ECPGSetAutocommit
140         {
141                 fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
142                 whenever_action(2);
143                 free($1);
144         }
145         | ECPGSetConnection
146         {
147                 if (connection)
148                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in SET CONNECTION statement");
149
150                 fprintf(yyout, "{ ECPGsetconn(__LINE__, %s);", $1);
151                 whenever_action(2);
152                 free($1);
153         }
154         | ECPGSetDescriptor
155         {
156                 lookup_descriptor($1.name, connection);
157                 output_set_descr($1.name, $1.str);
158                 free($1.name);
159                 free($1.str);
160         }
161         | ECPGSetDescriptorHeader
162         {
163                 lookup_descriptor($1, connection);
164                 output_set_descr_header($1);
165                 free($1);
166         }
167         | ECPGTypedef
168         {
169                 if (connection)
170                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in TYPE statement");
171
172                 fprintf(yyout, "%s", $1);
173                 free($1);
174                 output_line_number();
175         }
176         | ECPGVar
177         {
178                 if (connection)
179                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in VAR statement");
180
181                 output_simple_statement($1);
182         }
183         | ECPGWhenever
184         {
185                 if (connection)
186                         mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER statement");
187
188                 output_simple_statement($1);
189         }
190 ECPG: where_or_current_clauseWHERECURRENT_POFcursor_name block
191         {
192                 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
193                 $$ = cat_str(2,mm_strdup("where current of"), cursor_marker);
194         }
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
200                 if ($1[0] == '$')
201                 {
202                         free($1);
203                         $1 = mm_strdup("$0");
204                 }
205 ECPG: fetch_argscursor_name addon
206                 add_additional_variables($1, false);
207                 if ($1[0] == ':')
208                 {
209                         free($1);
210                         $1 = mm_strdup("$0");
211                 }
212 ECPG: fetch_argsfrom_incursor_name addon
213                 add_additional_variables($2, false);
214                 if ($2[0] == ':')
215                 {
216                         free($2);
217                         $2 = mm_strdup("$0");
218                 }
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);
225                 if ($3[0] == ':')
226                 {
227                         free($3);
228                         $3 = mm_strdup("$0");
229                 }
230 ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
231                 add_additional_variables($3, false);
232                 if ($3[0] == ':')
233                 {
234                         free($3);
235                         $3 = mm_strdup("$0");
236                 }
237                 if ($1[0] == '$')
238                 {
239                         free($1);
240                         $1 = mm_strdup("$0");
241                 }
242 ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
243 ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
244                 add_additional_variables($4, false);
245                 if ($4[0] == ':')
246                 {
247                         free($4);
248                         $4 = mm_strdup("$0");
249                 }
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);
255                 if ($4[0] == ':')
256                 {
257                         free($4);
258                         $4 = mm_strdup("$0");
259                 }
260                 if ($2[0] == '$')
261                 {
262                         free($2);
263                         $2 = mm_strdup("$0");
264                 }
265 ECPG: cursor_namename rule
266         | char_civar
267                 {
268                         char *curname = mm_alloc(strlen($1) + 2);
269                         sprintf(curname, ":%s", $1);
270                         free($1);
271                         $1 = curname;
272                         $$ = $1;
273                 }
274 ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
275         {
276                 $$.name = $2;
277                 $$.type = $3;
278                 $$.stmt = cat_str(3, mm_strdup("\""), $5, mm_strdup("\""));
279         }
280         | PREPARE prepared_name FROM execstring
281         {
282                 $$.name = $2;
283                 $$.type = NULL;
284                 $$.stmt = $4;
285         }
286 ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
287         { $$ = $2; }
288 ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
289         {
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);
294
295                 for (ptr = cur; ptr != NULL; ptr = ptr->next)
296                 {
297                         if (strcmp_fn($2, ptr->name) == 0)
298                         {
299                                 if ($2[0] == ':')
300                                         mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", $2+1);
301                                 else
302                                         mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", $2);
303                         }
304                 }
305
306                 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
307
308                 this->next = cur;
309                 this->name = $2;
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;
319                 cur = this;
320
321                 c1 = mm_strdup(this->command);
322                 if ((c2 = strstr(c1, "*/")) != NULL)
323                 {
324                         /* We put this text into a comment, so we better remove [*][/]. */
325                         c2[0] = '.';
326                         c2[1] = '.';
327                 }
328                 comment = cat_str(3, mm_strdup("/*"), c1, mm_strdup("*/"));
329
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();"),
333                                 comment);
334                 else
335                         $$ = cat2_str(adjust_outofscope_cursor_vars(this), comment);
336         }
337 ECPG: ClosePortalStmtCLOSEcursor_name block
338         {
339                 char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : $2;
340                 $$ = cat2_str(mm_strdup("close"), cursor_marker);
341         }
342 ECPG: opt_hold block
343         {
344                 if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit)
345                         $$ = mm_strdup("with hold");
346                 else
347                         $$ = EMPTY;
348         }
349 ECPG: into_clauseINTOOptTempTableName block
350                                         {
351                                                 FoundInto = 1;
352                                                 $$= cat2_str(mm_strdup("into"), $2);
353                                         }
354         | ecpg_into { $$ = EMPTY; }
355 ECPG: table_refselect_with_parensopt_alias_clause addon
356         if ($2 == NULL)
357                 mmerror(PARSE_ERROR, ET_ERROR, "subquery in FROM must have an alias");
358 ECPG: table_refLATERAL_Pselect_with_parensopt_alias_clause addon
359         if ($3 == NULL)
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
366         {
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("[]"));
374         }
375         | opt_array_bounds '[' Iresult ']'
376         {
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("]"));
384         }
385 ECPG: opt_array_bounds
386         {
387                 $$.index1 = mm_strdup("-1");
388                 $$.index2 = mm_strdup("-1");
389                 $$.str= EMPTY;
390         }
391 ECPG: IconstICONST block
392         { $$ = make_name(); }
393 ECPG: AexprConstNULL_P rule
394         | civar                 { $$ = $1; }
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
406         {
407                 mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
408                 $$ = EMPTY;
409         }
410 ECPG: FetchStmtMOVEfetch_args rule
411         | FETCH fetch_args ecpg_fetch_into
412         {
413                 $$ = cat2_str(mm_strdup("fetch"), $2);
414         }
415         | FETCH FORWARD cursor_name opt_ecpg_fetch_into
416         {
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);
420         }
421         | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
422         {
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);
426         }
427         | FETCH BACKWARD cursor_name opt_ecpg_fetch_into
428         {
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);
432         }
433         | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
434         {
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);
438         }
439         | MOVE FORWARD cursor_name
440         {
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);
444         }
445         | MOVE FORWARD from_in cursor_name
446         {
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);
450         }
451         | MOVE BACKWARD cursor_name
452         {
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);
456         }
457         | MOVE BACKWARD from_in cursor_name
458         {
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);
462         }
463 ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
464         {
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);
467         }
468 ECPG: SignedIconstIconst rule
469         | civar { $$ = $1; }