diff options
Diffstat (limited to 'src/interfaces/ecpg/preproc/ecpg.addons')
| -rw-r--r-- | src/interfaces/ecpg/preproc/ecpg.addons | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg.addons b/src/interfaces/ecpg/preproc/ecpg.addons index 86be5041e9f..e8052819b0d 100644 --- a/src/interfaces/ecpg/preproc/ecpg.addons +++ b/src/interfaces/ecpg/preproc/ecpg.addons @@ -1,22 +1,6 @@ /* src/interfaces/ecpg/preproc/ecpg.addons */ ECPG: stmtClosePortalStmt block - { - if (INFORMIX_MODE) - { - if (pg_strcasecmp($1+strlen("close "), "database") == 0) - { - if (connection) - mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CLOSE DATABASE statement"); - - fprintf(base_yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");"); - whenever_action(2); - free($1); - break; - } - } - - output_statement($1, 0, ECPGst_normal); - } + { $$ = $1;} ECPG: stmtDeallocateStmt block { output_deallocate_prepare_statement($1); @@ -25,7 +9,11 @@ ECPG: stmtDeclareCursorStmt block { output_simple_statement($1, (strncmp($1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0); } ECPG: stmtDiscardStmt block ECPG: stmtFetchStmt block - { output_statement($1, 1, ECPGst_normal); } + { + /* g_cursor_name is set in the fetch_args block and freed in the output_cursor_statement */ + output_cursor_statement(ECPGcst_fetch, g_cursor_name, NULL, $1, 1, ECPGst_normal); + g_cursor_name = NULL; + } ECPG: stmtDeleteStmt block ECPG: stmtInsertStmt block ECPG: stmtSelectStmt block @@ -63,6 +51,10 @@ ECPG: stmtViewStmt rule whenever_action(2); free($1); } + | ECPGDeclareStmt + { + output_declare_statement($1); + } | ECPGCursorStmt { output_simple_statement($1, (strncmp($1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0); @@ -132,7 +124,14 @@ ECPG: stmtViewStmt rule if ((ptr = add_additional_variables($1, true)) != NULL) { connection = ptr->connection ? mm_strdup(ptr->connection) : NULL; - output_statement(mm_strdup(ptr->command), 0, ECPGst_normal); + if (ptr->prepared_name) + { + output_cursor_statement(ECPGcst_open, $1, mm_strdup(ptr->prepared_name), mm_strdup(ptr->command), 0, ECPGst_normal); + } + else + { + output_cursor_statement(ECPGcst_open, $1, NULL, mm_strdup(ptr->command), 0, ECPGst_normal); + } ptr->opened = true; } } @@ -204,6 +203,7 @@ ECPG: var_valueNumericOnly addon } ECPG: fetch_argscursor_name addon add_additional_variables($1, false); + g_cursor_name = mm_strdup($1); if ($1[0] == ':') { free($1); @@ -211,6 +211,7 @@ ECPG: fetch_argscursor_name addon } ECPG: fetch_argsfrom_incursor_name addon add_additional_variables($2, false); + g_cursor_name = mm_strdup($2); if ($2[0] == ':') { free($2); @@ -222,6 +223,7 @@ ECPG: fetch_argsFIRST_Popt_from_incursor_name addon ECPG: fetch_argsLAST_Popt_from_incursor_name addon ECPG: fetch_argsALLopt_from_incursor_name addon add_additional_variables($3, false); + g_cursor_name = mm_strdup($3); if ($3[0] == ':') { free($3); @@ -229,6 +231,7 @@ ECPG: fetch_argsALLopt_from_incursor_name addon } ECPG: fetch_argsSignedIconstopt_from_incursor_name addon add_additional_variables($3, false); + g_cursor_name = mm_strdup($3); if ($3[0] == ':') { free($3); @@ -242,6 +245,7 @@ ECPG: fetch_argsSignedIconstopt_from_incursor_name addon ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon add_additional_variables($4, false); + g_cursor_name = mm_strdup($4); if ($4[0] == ':') { free($4); @@ -252,6 +256,7 @@ ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon add_additional_variables($4, false); + g_cursor_name = mm_strdup($4); if ($4[0] == ':') { free($4); @@ -304,6 +309,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt } this = (struct cursor *) mm_alloc(sizeof(struct cursor)); + memset(this, 0 ,sizeof(struct cursor)); this->next = cur; this->name = $2; @@ -331,8 +337,31 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt } ECPG: ClosePortalStmtCLOSEcursor_name block { + char *stmt = NULL; + char *cursor_name = NULL; char *cursor_marker = $2[0] == ':' ? mm_strdup("$0") : $2; - $$ = cat2_str(mm_strdup("close"), cursor_marker); + + cursor_name = mm_strdup($2); + + stmt = cat2_str(mm_strdup("close"), cursor_marker); + + if (INFORMIX_MODE) + { + if (pg_strcasecmp(stmt+strlen("close "), "database") == 0) + { + if (connection) + mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CLOSE DATABASE statement"); + + fprintf(base_yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");"); + whenever_action(2); + free(stmt); + break; + } + } + + output_cursor_statement(ECPGcst_close, cursor_name, NULL, stmt, 0, ECPGst_normal); + + $$ = EMPTY; } ECPG: opt_hold block { @@ -411,48 +440,56 @@ ECPG: FetchStmtMOVEfetch_args rule { char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3; add_additional_variables($3, false); + g_cursor_name = mm_strdup($3); $$ = cat_str(2, mm_strdup("fetch forward"), cursor_marker); } | FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into { char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4; add_additional_variables($4, false); + g_cursor_name = mm_strdup($4); $$ = cat_str(2, mm_strdup("fetch forward from"), cursor_marker); } | FETCH BACKWARD cursor_name opt_ecpg_fetch_into { char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3; add_additional_variables($3, false); + g_cursor_name = mm_strdup($3); $$ = cat_str(2, mm_strdup("fetch backward"), cursor_marker); } | FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into { char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4; add_additional_variables($4, false); + g_cursor_name = mm_strdup($4); $$ = cat_str(2, mm_strdup("fetch backward from"), cursor_marker); } | MOVE FORWARD cursor_name { char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3; add_additional_variables($3, false); + g_cursor_name = mm_strdup($3); $$ = cat_str(2, mm_strdup("move forward"), cursor_marker); } | MOVE FORWARD from_in cursor_name { char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4; add_additional_variables($4, false); + g_cursor_name = mm_strdup($4); $$ = cat_str(2, mm_strdup("move forward from"), cursor_marker); } | MOVE BACKWARD cursor_name { char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3; add_additional_variables($3, false); + g_cursor_name = mm_strdup($3); $$ = cat_str(2, mm_strdup("move backward"), cursor_marker); } | MOVE BACKWARD from_in cursor_name { char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4; add_additional_variables($4, false); + g_cursor_name = mm_strdup($4); $$ = cat_str(2, mm_strdup("move backward from"), cursor_marker); } ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block |
