@@ -33,6 +33,7 @@ ECPG: stmtUpdateStmt block
3333 { output_statement($1, 1, ECPGst_prepnormal); }
3434ECPG: stmtExecuteStmt block
3535 {
36+ check_declared_list($1.name);
3637 if ($1.type == NULL || strlen($1.type) == 0)
3738 output_statement($1.name, 1, ECPGst_execute);
3839 else
@@ -56,6 +57,7 @@ ECPG: stmtExecuteStmt block
5657 }
5758ECPG: stmtPrepareStmt block
5859 {
60+ check_declared_list($1.name);
5961 if ($1.type == NULL)
6062 output_prepare_statement($1.name, $1.stmt);
6163 else if (strlen($1.type) == 0)
@@ -104,6 +106,10 @@ ECPG: stmtViewStmt rule
104106 whenever_action(2);
105107 free($1);
106108 }
109+ | ECPGDeclareStmt
110+ {
111+ output_simple_statement($1, 0);
112+ }
107113 | ECPGCursorStmt
108114 {
109115 output_simple_statement($1, (strncmp($1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0);
@@ -244,14 +250,20 @@ ECPG: var_valueNumericOnly addon
244250 $1 = mm_strdup("$0");
245251 }
246252ECPG: fetch_argscursor_name addon
247- add_additional_variables($1, false);
253+ struct cursor *ptr = add_additional_variables($1, false);
254+ if (ptr -> connection)
255+ connection = mm_strdup(ptr -> connection);
256+
248257 if ($1[0] == ':')
249258 {
250259 free($1);
251260 $1 = mm_strdup("$0");
252261 }
253262ECPG: fetch_argsfrom_incursor_name addon
254- add_additional_variables($2, false);
263+ struct cursor *ptr = add_additional_variables($2, false);
264+ if (ptr -> connection)
265+ connection = mm_strdup(ptr -> connection);
266+
255267 if ($2[0] == ':')
256268 {
257269 free($2);
@@ -262,14 +274,20 @@ ECPG: fetch_argsPRIORopt_from_incursor_name addon
262274ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
263275ECPG: fetch_argsLAST_Popt_from_incursor_name addon
264276ECPG: fetch_argsALLopt_from_incursor_name addon
265- add_additional_variables($3, false);
277+ struct cursor *ptr = add_additional_variables($3, false);
278+ if (ptr -> connection)
279+ connection = mm_strdup(ptr -> connection);
280+
266281 if ($3[0] == ':')
267282 {
268283 free($3);
269284 $3 = mm_strdup("$0");
270285 }
271286ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
272- add_additional_variables($3, false);
287+ struct cursor *ptr = add_additional_variables($3, false);
288+ if (ptr -> connection)
289+ connection = mm_strdup(ptr -> connection);
290+
273291 if ($3[0] == ':')
274292 {
275293 free($3);
@@ -282,7 +300,10 @@ ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
282300 }
283301ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
284302ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
285- add_additional_variables($4, false);
303+ struct cursor *ptr = add_additional_variables($4, false);
304+ if (ptr -> connection)
305+ connection = mm_strdup(ptr -> connection);
306+
286307 if ($4[0] == ':')
287308 {
288309 free($4);
@@ -292,7 +313,10 @@ ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon
292313ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
293314ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
294315ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
295- add_additional_variables($4, false);
316+ struct cursor *ptr = add_additional_variables($4, false);
317+ if (ptr -> connection)
318+ connection = mm_strdup(ptr -> connection);
319+
296320 if ($4[0] == ':')
297321 {
298322 free($4);
@@ -348,6 +372,9 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
348372 char *comment, *c1, *c2;
349373 int (* strcmp_fn)(const char *, const char *) = (($2[0] == ':' || $2[0] == '"') ? strcmp : pg_strcasecmp);
350374
375+ if (INFORMIX_MODE && pg_strcasecmp($2, "database") == 0)
376+ mmfatal(PARSE_ERROR, "\"database\" cannot be used as cursor name in INFORMIX mode");
377+
351378 for (ptr = cur; ptr != NULL; ptr = ptr->next)
352379 {
353380 if (strcmp_fn($2, ptr->name) == 0)
@@ -388,6 +415,17 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
388415ECPG: ClosePortalStmtCLOSEcursor_name block
389416 {
390417 char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : $2;
418+ struct cursor *ptr = NULL;
419+ for (ptr = cur; ptr != NULL; ptr = ptr -> next)
420+ {
421+ if (strcmp($2, ptr -> name) == 0)
422+ {
423+ if (ptr -> connection)
424+ connection = mm_strdup(ptr -> connection);
425+
426+ break;
427+ }
428+ }
391429 $$ = cat2_str(mm_strdup("close"), cursor_marker);
392430 }
393431ECPG: opt_hold block
@@ -466,49 +504,73 @@ ECPG: FetchStmtMOVEfetch_args rule
466504 | FETCH FORWARD cursor_name opt_ecpg_fetch_into
467505 {
468506 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
469- add_additional_variables($3, false);
507+ struct cursor *ptr = add_additional_variables($3, false);
508+ if (ptr -> connection)
509+ connection = mm_strdup(ptr -> connection);
510+
470511 $$ = cat_str(2, mm_strdup("fetch forward"), cursor_marker);
471512 }
472513 | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
473514 {
474515 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
475- add_additional_variables($4, false);
516+ struct cursor *ptr = add_additional_variables($4, false);
517+ if (ptr -> connection)
518+ connection = mm_strdup(ptr -> connection);
519+
476520 $$ = cat_str(2, mm_strdup("fetch forward from"), cursor_marker);
477521 }
478522 | FETCH BACKWARD cursor_name opt_ecpg_fetch_into
479523 {
480524 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
481- add_additional_variables($3, false);
525+ struct cursor *ptr = add_additional_variables($3, false);
526+ if (ptr -> connection)
527+ connection = mm_strdup(ptr -> connection);
528+
482529 $$ = cat_str(2, mm_strdup("fetch backward"), cursor_marker);
483530 }
484531 | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
485532 {
486533 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
487- add_additional_variables($4, false);
534+ struct cursor *ptr = add_additional_variables($4, false);
535+ if (ptr -> connection)
536+ connection = mm_strdup(ptr -> connection);
537+
488538 $$ = cat_str(2, mm_strdup("fetch backward from"), cursor_marker);
489539 }
490540 | MOVE FORWARD cursor_name
491541 {
492542 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
493- add_additional_variables($3, false);
543+ struct cursor *ptr = add_additional_variables($3, false);
544+ if (ptr -> connection)
545+ connection = mm_strdup(ptr -> connection);
546+
494547 $$ = cat_str(2, mm_strdup("move forward"), cursor_marker);
495548 }
496549 | MOVE FORWARD from_in cursor_name
497550 {
498551 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
499- add_additional_variables($4, false);
552+ struct cursor *ptr = add_additional_variables($4, false);
553+ if (ptr -> connection)
554+ connection = mm_strdup(ptr -> connection);
555+
500556 $$ = cat_str(2, mm_strdup("move forward from"), cursor_marker);
501557 }
502558 | MOVE BACKWARD cursor_name
503559 {
504560 char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
505- add_additional_variables($3, false);
561+ struct cursor *ptr = add_additional_variables($3, false);
562+ if (ptr -> connection)
563+ connection = mm_strdup(ptr -> connection);
564+
506565 $$ = cat_str(2, mm_strdup("move backward"), cursor_marker);
507566 }
508567 | MOVE BACKWARD from_in cursor_name
509568 {
510569 char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
511- add_additional_variables($4, false);
570+ struct cursor *ptr = add_additional_variables($4, false);
571+ if (ptr -> connection)
572+ connection = mm_strdup(ptr -> connection);
573+
512574 $$ = cat_str(2, mm_strdup("move backward from"), cursor_marker);
513575 }
514576ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
0 commit comments