From 2ea179f36102edc8df6be9e728b24bcb264ec52e Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Wed, 11 Nov 2009 19:25:42 +0000 Subject: Support optional FROM/IN in FETCH and MOVE The main motivation for this is that it's required for Informix compatibility in ECPG. This patch makes the ECPG and core grammars a bit closer to one another for these productions. Author: Zoltan Boszormenyi --- src/interfaces/ecpg/preproc/ecpg.addons | 76 +++++++++------------- .../test/expected/compat_informix-test_informix.c | 2 +- .../expected/compat_informix-test_informix.stderr | 6 +- 3 files changed, 35 insertions(+), 49 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/ecpg/preproc/ecpg.addons b/src/interfaces/ecpg/preproc/ecpg.addons index 75506161700..9ef3d191009 100644 --- a/src/interfaces/ecpg/preproc/ecpg.addons +++ b/src/interfaces/ecpg/preproc/ecpg.addons @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.6 2009/11/05 23:24:27 tgl Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.7 2009/11/11 19:25:40 alvherre Exp $ */ ECPG: stmtClosePortalStmt block { @@ -206,16 +206,38 @@ ECPG: ConstraintAttributeSpecConstraintTimeSpecConstraintDeferrabilitySpec addon if (strcmp($2, "deferrable") != 0 && strcmp($1, "initially deferrable") == 0 ) mmerror(PARSE_ERROR, ET_ERROR, "constraint declared INITIALLY DEFERRED must be DEFERRABLE"); ECPG: var_valueNumericOnly addon -ECPG: fetch_directionSignedIconst addon if ($1[0] == '$') { free($1); $1 = make_str("$0"); } -ECPG: fetch_directionABSOLUTE_PSignedIconst addon -ECPG: fetch_directionRELATIVE_PSignedIconst addon -ECPG: fetch_directionFORWARDSignedIconst addon -ECPG: fetch_directionBACKWARDSignedIconst addon +ECPG: fetch_argsname addon + add_additional_variables($1, false); +ECPG: fetch_argsfrom_inname addon + add_additional_variables($2, false); +ECPG: fetch_argsNEXTopt_from_inname addon +ECPG: fetch_argsPRIORopt_from_inname addon +ECPG: fetch_argsFIRST_Popt_from_inname addon +ECPG: fetch_argsLAST_Popt_from_inname addon +ECPG: fetch_argsALLopt_from_inname addon +ECPG: fetch_argsFORWARDopt_from_inname addon +ECPG: fetch_argsBACKWARDopt_from_inname addon + add_additional_variables($3, false); +ECPG: fetch_argsSignedIconstopt_from_inname addon + add_additional_variables($3, false); + if ($1[0] == '$') + { + free($1); + $1 = make_str("$0"); + } +ECPG: fetch_argsFORWARDALLopt_from_inname addon +ECPG: fetch_argsBACKWARDALLopt_from_inname addon + add_additional_variables($4, false); +ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_inname addon +ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_inname addon +ECPG: fetch_argsFORWARDSignedIconstopt_from_inname addon +ECPG: fetch_argsBACKWARDSignedIconstopt_from_inname addon + add_additional_variables($4, false); if ($2[0] == '$') { free($2); @@ -336,47 +358,11 @@ ECPG: VariableShowStmtSHOWALL block mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented"); $$ = EMPTY; } -ECPG: FetchStmtFETCHfetch_directionfrom_inname block - { - add_additional_variables($4, false); - $$ = cat_str(4, make_str("fetch"), $2, $3, $4); - } -ECPG: FetchStmtFETCHname block +ECPG: FetchStmtMOVEfetch_args rule + | FETCH fetch_args ecpg_into { - add_additional_variables($2, false); - $$ = cat_str(2, make_str("fetch"), $2); + $$ = cat2_str(make_str("fetch"), $2); } -ECPG: FetchStmtMOVEname rule - | FETCH fetch_direction from_in name ecpg_into - { - add_additional_variables($4, false); - $$ = cat_str(4, make_str("fetch"), $2, $3, $4); - } - | FETCH fetch_direction name ecpg_into - { - add_additional_variables($3, false); - $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3); - } - | FETCH from_in name ecpg_into - { - add_additional_variables($3, false); - $$ = cat_str(3, make_str("fetch"), $2, $3); - } - | FETCH name ecpg_into - { - add_additional_variables($2, false); - $$ = cat2_str(make_str("fetch"), $2); - } - | FETCH fetch_direction name - { - add_additional_variables($3, false); - $$ = cat_str(4, make_str("fetch"), $2, make_str("from"), $3); - } - | FETCH from_in name - { - add_additional_variables($3, false); - $$ = cat_str(3, make_str("fetch"), $2, $3); - } ECPG: select_limitLIMITselect_limit_value','select_offset_value block { mmerror(PARSE_ERROR, ET_WARNING, "no longer supported LIMIT #,# syntax passed to server"); diff --git a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c index 3d48a3a273b..0dc8c7f08ad 100644 --- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c +++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c @@ -158,7 +158,7 @@ if (sqlca.sqlcode < 0) dosqlprint ( );} while (1) { - { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward from c", ECPGt_EOIT, + { ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, ECPGt_int,&(i),(long)1,(long)1,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), diff --git a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr index 89e9483ffb9..d678788640c 100644 --- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr +++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr @@ -63,7 +63,7 @@ DETAIL: Key (i)=(7) already exists. [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 95: OK: DECLARE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 57: query: fetch forward from c; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 57: query: fetch forward c; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 57: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 @@ -75,7 +75,7 @@ DETAIL: Key (i)=(7) already exists. [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_get_data on line 57: RESULT: test offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 57: query: fetch forward from c; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 57: query: fetch forward c; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 57: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 @@ -87,7 +87,7 @@ DETAIL: Key (i)=(7) already exists. [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_get_data on line 57: RESULT: a offset: -1; array: yes [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 57: query: fetch forward from c; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 57: query: fetch forward c; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 57: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -- cgit v1.2.3