Debian Codegraph @

src/interfaces/ecpg/preproc/ecpg.addons

raw
1 /* src/interfaces/ecpg/preproc/ecpg.addons */
2 ECPG: block stmt ClosePortalStmt
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(base_yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");");
12 whenever_action(2);
13 break;
14 }
15 }
16
17 output_statement(@1, 0, ECPGst_normal);
18 }
19 ECPG: block stmt DeallocateStmt
20 {
21 output_deallocate_prepare_statement(@1);
22 }
23 ECPG: block stmt DeclareCursorStmt
24 {
25 output_simple_statement(@1, (strncmp(@1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0);
26 }
27 ECPG: block stmt DiscardStmt
28 ECPG: block stmt FetchStmt
29 { output_statement(@1, 1, ECPGst_normal); }
30 ECPG: block stmt DeleteStmt
31 ECPG: block stmt InsertStmt
32 ECPG: block stmt SelectStmt
33 ECPG: block stmt UpdateStmt
34 { output_statement(@1, 1, ECPGst_prepnormal); }
35 ECPG: block stmt ExecuteStmt
36 {
37 check_declared_list($1.name);
38 if ($1.type == NULL || strlen($1.type) == 0)
39 output_statement($1.name, 1, ECPGst_execute);
40 else
41 {
42 if ($1.name[0] != '"')
43 /* case of char_variable */
44 add_variable_to_tail(&argsinsert, find_variable($1.name), &no_indicator);
45 else
46 {
47 /* case of ecpg_ident or CSTRING */
48 char length[32];
49 char *str;
50
51 /* Remove double quotes from name */
52 str = loc_strdup($1.name + 1);
53 str[strlen(str) - 1] = '\0';
54 snprintf(length, sizeof(length), "%zu", strlen(str));
55 add_variable_to_tail(&argsinsert, new_variable(str, ECPGmake_simple_type(ECPGt_const, length, 0), 0), &no_indicator);
56 }
57 output_statement(cat_str(3, "execute", "$0", $1.type), 0, ECPGst_exec_with_exprlist);
58 }
59 }
60 ECPG: block stmt PrepareStmt
61 {
62 check_declared_list($1.name);
63 if ($1.type == NULL)
64 output_prepare_statement($1.name, $1.stmt);
65 else if (strlen($1.type) == 0)
66 {
67 char *stmt = cat_str(3, "\"", $1.stmt, "\"");
68
69 output_prepare_statement($1.name, stmt);
70 }
71 else
72 {
73 if ($1.name[0] != '"')
74 /* case of char_variable */
75 add_variable_to_tail(&argsinsert, find_variable($1.name), &no_indicator);
76 else
77 {
78 char length[32];
79 char *str;
80
81 /* Remove double quotes from name */
82 str = loc_strdup($1.name + 1);
83 str[strlen(str) - 1] = '\0';
84 snprintf(length, sizeof(length), "%zu", strlen(str));
85 add_variable_to_tail(&argsinsert, new_variable(str, ECPGmake_simple_type(ECPGt_const, length, 0), 0), &no_indicator);
86 }
87 output_statement(cat_str(5, "prepare", "$0", $1.type, "as", $1.stmt), 0, ECPGst_prepare);
88 }
89 }
90 ECPG: block stmt TransactionStmt
91 {
92 fprintf(base_yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", @1);
93 whenever_action(2);
94 }
95 ECPG: block toplevel_stmt TransactionStmtLegacy
96 {
97 fprintf(base_yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", @1);
98 whenever_action(2);
99 }
100 ECPG: rule stmt ViewStmt
101 | ECPGAllocateDescr
102 {
103 fprintf(base_yyout, "ECPGallocate_desc(__LINE__, %s);", @1);
104 whenever_action(0);
105 }
106 | ECPGConnect
107 {
108 if (connection)
109 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CONNECT statement");
110
111 fprintf(base_yyout, "{ ECPGconnect(__LINE__, %d, %s, %d); ", compat, @1, autocommit);
112 reset_variables();
113 whenever_action(2);
114 }
115 | ECPGDeclareStmt
116 {
117 output_simple_statement(@1, 0);
118 }
119 | ECPGCursorStmt
120 {
121 output_simple_statement(@1, (strncmp(@1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0);
122 }
123 | ECPGDeallocateDescr
124 {
125 fprintf(base_yyout, "ECPGdeallocate_desc(__LINE__, %s);", @1);
126 whenever_action(0);
127 }
128 | ECPGDeclare
129 {
130 output_simple_statement(@1, 0);
131 }
132 | ECPGDescribe
133 {
134 check_declared_list($1.stmt_name);
135
136 fprintf(base_yyout, "{ ECPGdescribe(__LINE__, %d, %d, %s, %s,", compat, $1.input, connection ? connection : "NULL", $1.stmt_name);
137 dump_variables(argsresult, 1);
138 argsresult = NULL;
139 fputs("ECPGt_EORT);", base_yyout);
140 fprintf(base_yyout, "}");
141 output_line_number();
142 }
143 | ECPGDisconnect
144 {
145 if (connection)
146 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in DISCONNECT statement");
147
148 fprintf(base_yyout, "{ ECPGdisconnect(__LINE__, %s);",
149 @1 ? @1 : "\"CURRENT\"");
150 whenever_action(2);
151 }
152 | ECPGExecuteImmediateStmt
153 {
154 output_statement(@1, 0, ECPGst_exec_immediate);
155 }
156 | ECPGFree
157 {
158 const char *con = connection ? connection : "NULL";
159
160 if (strcmp(@1, "all") == 0)
161 fprintf(base_yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
162 else if (@1[0] == ':')
163 fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, %s);", compat, con, @1 + 1);
164 else
165 fprintf(base_yyout, "{ ECPGdeallocate(__LINE__, %d, %s, \"%s\");", compat, con, @1);
166
167 whenever_action(2);
168 }
169 | ECPGGetDescriptor
170 {
171 lookup_descriptor($1.name, connection);
172 output_get_descr($1.name, $1.str);
173 }
174 | ECPGGetDescriptorHeader
175 {
176 lookup_descriptor(@1, connection);
177 output_get_descr_header(@1);
178 }
179 | ECPGOpen
180 {
181 struct cursor *ptr;
182
183 if ((ptr = add_additional_variables(@1, true)) != NULL)
184 {
185 free(connection);
186 connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
187 output_statement(ptr->command, 0, ECPGst_normal);
188 ptr->opened = true;
189 }
190 }
191 | ECPGSetAutocommit
192 {
193 fprintf(base_yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", @1, connection ? connection : "NULL");
194 whenever_action(2);
195 }
196 | ECPGSetConnection
197 {
198 if (connection)
199 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in SET CONNECTION statement");
200
201 fprintf(base_yyout, "{ ECPGsetconn(__LINE__, %s);", @1);
202 whenever_action(2);
203 }
204 | ECPGSetDescriptor
205 {
206 lookup_descriptor($1.name, connection);
207 output_set_descr($1.name, $1.str);
208 }
209 | ECPGSetDescriptorHeader
210 {
211 lookup_descriptor(@1, connection);
212 output_set_descr_header(@1);
213 }
214 | ECPGTypedef
215 {
216 if (connection)
217 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in TYPE statement");
218
219 fprintf(base_yyout, "%s", @1);
220 output_line_number();
221 }
222 | ECPGVar
223 {
224 if (connection)
225 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in VAR statement");
226
227 output_simple_statement(@1, 0);
228 }
229 | ECPGWhenever
230 {
231 if (connection)
232 mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER statement");
233
234 output_simple_statement(@1, 0);
235 }
236 ECPG: block where_or_current_clause WHERE CURRENT_P OF cursor_name
237 {
238 const char *cursor_marker = @4[0] == ':' ? "$0" : @4;
239
240 @$ = cat_str(2, "where current of", cursor_marker);
241 }
242 ECPG: addon CopyStmt COPY opt_binary qualified_name opt_column_list copy_from opt_program copy_file_name copy_delimiter opt_with copy_options where_clause
243 if (strcmp(@5, "from") == 0 &&
244 (strcmp(@7, "stdin") == 0 || strcmp(@7, "stdout") == 0))
245 mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
246 ECPG: addon var_value NumericOnly
247 if (@1[0] == '$')
248 @$ = "$0";
249 ECPG: addon fetch_args cursor_name
250 struct cursor *ptr = add_additional_variables(@1, false);
251
252 update_connection(ptr->connection);
253 if (@1[0] == ':')
254 @$ = "$0";
255 ECPG: addon fetch_args from_in cursor_name
256 struct cursor *ptr = add_additional_variables(@2, false);
257
258 update_connection(ptr->connection);
259 if (@2[0] == ':')
260 @$ = cat2_str(@1, "$0");
261 ECPG: addon fetch_args NEXT opt_from_in cursor_name
262 ECPG: addon fetch_args PRIOR opt_from_in cursor_name
263 ECPG: addon fetch_args FIRST_P opt_from_in cursor_name
264 ECPG: addon fetch_args LAST_P opt_from_in cursor_name
265 ECPG: addon fetch_args ALL opt_from_in cursor_name
266 struct cursor *ptr = add_additional_variables(@3, false);
267
268 update_connection(ptr->connection);
269 if (@3[0] == ':')
270 @$ = cat_str(3, @1, @2, "$0");
271 ECPG: addon fetch_args SignedIconst opt_from_in cursor_name
272 struct cursor *ptr = add_additional_variables(@3, false);
273 bool replace = false;
274
275 update_connection(ptr->connection);
276 if (@3[0] == ':')
277 {
278 @3 = "$0";
279 replace = true;
280 }
281 if (@1[0] == '$')
282 {
283 @1 = "$0";
284 replace = true;
285 }
286 if (replace)
287 @$ = cat_str(3, @1, @2, @3);
288 ECPG: addon fetch_args FORWARD ALL opt_from_in cursor_name
289 ECPG: addon fetch_args BACKWARD ALL opt_from_in cursor_name
290 struct cursor *ptr = add_additional_variables(@4, false);
291
292 update_connection(ptr->connection);
293 if (@4[0] == ':')
294 @$ = cat_str(4, @1, @2, @3, "$0");
295 ECPG: addon fetch_args ABSOLUTE_P SignedIconst opt_from_in cursor_name
296 ECPG: addon fetch_args RELATIVE_P SignedIconst opt_from_in cursor_name
297 ECPG: addon fetch_args FORWARD SignedIconst opt_from_in cursor_name
298 ECPG: addon fetch_args BACKWARD SignedIconst opt_from_in cursor_name
299 struct cursor *ptr = add_additional_variables(@4, false);
300 bool replace = false;
301
302 update_connection(ptr->connection);
303 if (@4[0] == ':')
304 {
305 @4 = "$0";
306 replace = true;
307 }
308 if (@2[0] == '$')
309 {
310 @2 = "$0";
311 replace = true;
312 }
313 if (replace)
314 @$ = cat_str(4, @1, @2, @3, @4);
315 ECPG: block cursor_name name
316 | char_civar
317 {
318 char *curname = loc_alloc(strlen(@1) + 2);
319
320 sprintf(curname, ":%s", @1);
321 @$ = curname;
322 }
323 ECPG: block ExplainableStmt ExecuteStmt
324 {
325 @$ = $1.name;
326 }
327 ECPG: block PrepareStmt PREPARE prepared_name prep_type_clause AS PreparableStmt
328 {
329 $$.name = @2;
330 $$.type = @3;
331 $$.stmt = @5;
332 }
333 | PREPARE prepared_name FROM execstring
334 {
335 $$.name = @2;
336 $$.type = NULL;
337 $$.stmt = @4;
338 }
339 ECPG: block ExecuteStmt EXECUTE prepared_name execute_param_clause execute_rest
340 {
341 $$.name = @2;
342 $$.type = @3;
343 }
344 ECPG: block ExecuteStmt CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause opt_with_data execute_rest
345 {
346 $$.name = @$;
347 }
348 ECPG: block ExecuteStmt CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS EXECUTE prepared_name execute_param_clause opt_with_data execute_rest
349 {
350 $$.name = @$;
351 }
352 ECPG: block DeclareCursorStmt DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
353 {
354 struct cursor *ptr,
355 *this;
356 const char *cursor_marker = @2[0] == ':' ? "$0" : @2;
357 char *comment,
358 *c1,
359 *c2;
360 int (*strcmp_fn) (const char *, const char *) = ((@2[0] == ':' || @2[0] == '"') ? strcmp : pg_strcasecmp);
361
362 if (INFORMIX_MODE && pg_strcasecmp(@2, "database") == 0)
363 mmfatal(PARSE_ERROR, "\"database\" cannot be used as cursor name in INFORMIX mode");
364
365 for (ptr = cur; ptr != NULL; ptr = ptr->next)
366 {
367 if (strcmp_fn(@2, ptr->name) == 0)
368 {
369 if (@2[0] == ':')
370 mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", @2 + 1);
371 else
372 mmerror(PARSE_ERROR, ET_ERROR, "cursor \"%s\" is already defined", @2);
373 }
374 }
375
376 this = (struct cursor *) mm_alloc(sizeof(struct cursor));
377
378 this->next = cur;
379 this->name = mm_strdup(@2);
380 this->function = (current_function ? mm_strdup(current_function) : NULL);
381 this->connection = connection ? mm_strdup(connection) : NULL;
382 this->opened = false;
383 this->command = mm_strdup(cat_str(7, "declare", cursor_marker, @3, "cursor", @5, "for", @7));
384 this->argsinsert = argsinsert;
385 this->argsinsert_oos = NULL;
386 this->argsresult = argsresult;
387 this->argsresult_oos = NULL;
388 argsinsert = argsresult = NULL;
389 cur = this;
390
391 c1 = loc_strdup(this->command);
392 while ((c2 = strstr(c1, "*/")) != NULL)
393 {
394 /* We put this text into a comment, so we better remove [*][/]. */
395 c2[0] = '.';
396 c2[1] = '.';
397 }
398 comment = cat_str(3, "/*", c1, "*/");
399
400 @$ = cat2_str(adjust_outofscope_cursor_vars(this), comment);
401 }
402 ECPG: block ClosePortalStmt CLOSE cursor_name
403 {
404 const char *cursor_marker = @2[0] == ':' ? "$0" : @2;
405 struct cursor *ptr = NULL;
406
407 for (ptr = cur; ptr != NULL; ptr = ptr->next)
408 {
409 if (strcmp(@2, ptr->name) == 0)
410 {
411 update_connection(ptr->connection);
412 break;
413 }
414 }
415 @$ = cat2_str("close", cursor_marker);
416 }
417 ECPG: block opt_hold
418 {
419 if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit)
420 @$ = "with hold";
421 else
422 @$ = "";
423 }
424 ECPG: block into_clause INTO OptTempTableName
425 {
426 FoundInto = 1;
427 @$ = cat2_str("into", @2);
428 }
429 | ecpg_into
430 {
431 @$ = "";
432 }
433 ECPG: block Typename SimpleTypename opt_array_bounds
434 {
435 @$ = cat2_str(@1, $2.str);
436 }
437 ECPG: block Typename SETOF SimpleTypename opt_array_bounds
438 {
439 @$ = cat_str(3, "setof", @2, $3.str);
440 }
441 ECPG: block opt_array_bounds opt_array_bounds '[' ']'
442 {
443 $$.index1 = $1.index1;
444 $$.index2 = $1.index2;
445 if (strcmp($$.index1, "-1") == 0)
446 $$.index1 = "0";
447 else if (strcmp($1.index2, "-1") == 0)
448 $$.index2 = "0";
449 $$.str = cat_str(2, $1.str, "[]");
450 }
451 | opt_array_bounds '[' Iresult ']'
452 {
453 $$.index1 = $1.index1;
454 $$.index2 = $1.index2;
455 if (strcmp($1.index1, "-1") == 0)
456 $$.index1 = @3;
457 else if (strcmp($1.index2, "-1") == 0)
458 $$.index2 = @3;
459 $$.str = cat_str(4, $1.str, "[", @3, "]");
460 }
461 ECPG: block opt_array_bounds
462 {
463 $$.index1 = "-1";
464 $$.index2 = "-1";
465 $$.str = "";
466 }
467 ECPG: rule AexprConst NULL_P
468 | civar
469 | civarind
470 ECPG: block VariableShowStmt SHOW ALL
471 {
472 mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
473 }
474 ECPG: rule FetchStmt MOVE fetch_args
475 | FETCH fetch_args ecpg_fetch_into
476 | FETCH FORWARD cursor_name opt_ecpg_fetch_into
477 {
478 const char *cursor_marker = @3[0] == ':' ? "$0" : @3;
479 struct cursor *ptr = add_additional_variables(@3, false);
480
481 update_connection(ptr->connection);
482
483 @$ = cat_str(2, "fetch forward", cursor_marker);
484 }
485 | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
486 {
487 const char *cursor_marker = @4[0] == ':' ? "$0" : @4;
488 struct cursor *ptr = add_additional_variables(@4, false);
489
490 update_connection(ptr->connection);
491
492 @$ = cat_str(2, "fetch forward from", cursor_marker);
493 }
494 | FETCH BACKWARD cursor_name opt_ecpg_fetch_into
495 {
496 const char *cursor_marker = @3[0] == ':' ? "$0" : @3;
497 struct cursor *ptr = add_additional_variables(@3, false);
498
499 update_connection(ptr->connection);
500
501 @$ = cat_str(2, "fetch backward", cursor_marker);
502 }
503 | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
504 {
505 const char *cursor_marker = @4[0] == ':' ? "$0" : @4;
506 struct cursor *ptr = add_additional_variables(@4, false);
507
508 update_connection(ptr->connection);
509
510 @$ = cat_str(2, "fetch backward from", cursor_marker);
511 }
512 | MOVE FORWARD cursor_name
513 {
514 const char *cursor_marker = @3[0] == ':' ? "$0" : @3;
515 struct cursor *ptr = add_additional_variables(@3, false);
516
517 update_connection(ptr->connection);
518
519 @$ = cat_str(2, "move forward", cursor_marker);
520 }
521 | MOVE FORWARD from_in cursor_name
522 {
523 const char *cursor_marker = @4[0] == ':' ? "$0" : @4;
524 struct cursor *ptr = add_additional_variables(@4, false);
525
526 update_connection(ptr->connection);
527
528 @$ = cat_str(2, "move forward from", cursor_marker);
529 }
530 | MOVE BACKWARD cursor_name
531 {
532 const char *cursor_marker = @3[0] == ':' ? "$0" : @3;
533 struct cursor *ptr = add_additional_variables(@3, false);
534
535 update_connection(ptr->connection);
536
537 @$ = cat_str(2, "move backward", cursor_marker);
538 }
539 | MOVE BACKWARD from_in cursor_name
540 {
541 const char *cursor_marker = @4[0] == ':' ? "$0" : @4;
542 struct cursor *ptr = add_additional_variables(@4, false);
543
544 update_connection(ptr->connection);
545
546 @$ = cat_str(2, "move backward from", cursor_marker);
547 }
548 ECPG: block limit_clause LIMIT select_limit_value ',' select_offset_value
549 {
550 mmerror(PARSE_ERROR, ET_WARNING, "no longer supported LIMIT #,# syntax passed to server");
551 }
552 ECPG: rule SignedIconst Iconst
553 | civar