From 69b7d59a744134e33bbe51dab44dd4113c83b7fb Mon Sep 17 00:00:00 2001 From: Greg Stark Date: Mon, 29 Jul 2013 23:43:44 +0100 Subject: [PATCH] Sync ECPG with WITH ORDINALITY changes --- src/interfaces/ecpg/preproc/parse.pl | 1 + src/interfaces/ecpg/preproc/parser.c | 3 +++ .../ecpg/test/expected/sql-parser.c | 20 +------------------ .../ecpg/test/expected/sql-parser.stderr | 16 ++------------- src/interfaces/ecpg/test/sql/parser.pgc | 6 +++--- 5 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/interfaces/ecpg/preproc/parse.pl b/src/interfaces/ecpg/preproc/parse.pl index f4b51d679a..09310b330f 100644 --- a/src/interfaces/ecpg/preproc/parse.pl +++ b/src/interfaces/ecpg/preproc/parse.pl @@ -43,6 +43,7 @@ my %replace_token = ( # or in the block my %replace_string = ( 'WITH_TIME' => 'with time', + 'WITH_ORDINALITY' => 'with ordinality', 'NULLS_FIRST' => 'nulls first', 'NULLS_LAST' => 'nulls last', 'TYPECAST' => '::', diff --git a/src/interfaces/ecpg/preproc/parser.c b/src/interfaces/ecpg/preproc/parser.c index 2ce9dd91c0..c18615e2b0 100644 --- a/src/interfaces/ecpg/preproc/parser.c +++ b/src/interfaces/ecpg/preproc/parser.c @@ -108,6 +108,9 @@ filtered_base_yylex(void) case TIME: cur_token = WITH_TIME; break; + case ORDINALITY: + cur_token = WITH_ORDINALITY; + break; default: /* save the lookahead token for next time */ lookahead_token = next_token; diff --git a/src/interfaces/ecpg/test/expected/sql-parser.c b/src/interfaces/ecpg/test/expected/sql-parser.c index 876bbf34a1..a4a6d864bf 100644 --- a/src/interfaces/ecpg/test/expected/sql-parser.c +++ b/src/interfaces/ecpg/test/expected/sql-parser.c @@ -58,25 +58,7 @@ if (sqlca.sqlcode < 0) sqlprint();} #line 20 "parser.pgc" - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into T values ( 1 , null )", ECPGt_EOIT, ECPGt_EORT); -#line 22 "parser.pgc" - -if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 22 "parser.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 22 "parser.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into T values ( 1 , 1 )", ECPGt_EOIT, ECPGt_EORT); -#line 23 "parser.pgc" - -if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 23 "parser.pgc" - -if (sqlca.sqlcode < 0) sqlprint();} -#line 23 "parser.pgc" - - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into T values ( 1 , 2 )", ECPGt_EOIT, ECPGt_EORT); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t select 1 , nullif ( y - 1 , 0 ) from generate_series ( 1 , 3 ) with ordinality as series ( x , y )", ECPGt_EOIT, ECPGt_EORT); #line 24 "parser.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); diff --git a/src/interfaces/ecpg/test/expected/sql-parser.stderr b/src/interfaces/ecpg/test/expected/sql-parser.stderr index 0959fa1e72..af68c43db4 100644 --- a/src/interfaces/ecpg/test/expected/sql-parser.stderr +++ b/src/interfaces/ecpg/test/expected/sql-parser.stderr @@ -10,23 +10,11 @@ [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 20: OK: CREATE TABLE [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 22: query: insert into T values ( 1 , null ); with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 22: query: insert into t select 1 , nullif ( y - 1 , 0 ) from generate_series ( 1 , 3 ) with ordinality as series ( x , y ); with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 22: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 22: OK: INSERT 0 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 23: query: insert into T values ( 1 , 1 ); with 0 parameter(s) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 23: using PQexec -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 23: OK: INSERT 0 1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 24: query: insert into T values ( 1 , 2 ); with 0 parameter(s) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 24: using PQexec -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 24: OK: INSERT 0 1 +[NO_PID]: ecpg_execute on line 22: OK: INSERT 0 3 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 26: query: select Item2 from T order by Item2 nulls last; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/sql/parser.pgc b/src/interfaces/ecpg/test/sql/parser.pgc index e7115b9472..f569e43a1d 100644 --- a/src/interfaces/ecpg/test/sql/parser.pgc +++ b/src/interfaces/ecpg/test/sql/parser.pgc @@ -19,9 +19,9 @@ int main() { EXEC SQL CREATE TABLE T ( Item1 int, Item2 int ); - EXEC SQL INSERT INTO T VALUES ( 1, null ); - EXEC SQL INSERT INTO T VALUES ( 1, 1 ); - EXEC SQL INSERT INTO T VALUES ( 1, 2 ); + EXEC SQL INSERT INTO t + SELECT 1,nullif(y-1,0) + FROM generate_series(1,3) WITH ORDINALITY AS series(x,y); EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST;