From 98e4005efb1941c6422d6b8fbb5de27004149f7e Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Fri, 4 Jun 2010 10:09:58 +0000 Subject: [PATCH] Added variable handling for RETURNING clause to ecpg. While the values were correctly returned they were not moved into C variables as they should be. Closes: #5489 --- src/interfaces/ecpg/preproc/parse.pl | 3 ++- .../ecpg/test/expected/sql-insupd.c | 19 ++++++++++++------- .../ecpg/test/expected/sql-insupd.stderr | 16 ++++++++++++---- .../ecpg/test/expected/sql-insupd.stdout | 2 ++ src/interfaces/ecpg/test/sql/insupd.pgc | 7 ++++--- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/interfaces/ecpg/preproc/parse.pl b/src/interfaces/ecpg/preproc/parse.pl index 30217a35dc..1b59ead8f4 100644 --- a/src/interfaces/ecpg/preproc/parse.pl +++ b/src/interfaces/ecpg/preproc/parse.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.8 2010/05/30 18:10:41 tgl Exp $ +# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/parse.pl,v 1.9 2010/06/04 10:09:58 meskes Exp $ # parser generater for ecpg # call with backend parser as stdin # @@ -83,6 +83,7 @@ $replace_line{'VariableShowStmtSHOWvar_name'} = 'SHOW var_name ecpg_into'; $replace_line{'VariableShowStmtSHOWTIMEZONE'} = 'SHOW TIME ZONE ecpg_into'; $replace_line{'VariableShowStmtSHOWTRANSACTIONISOLATIONLEVEL'} = 'SHOW TRANSACTION ISOLATION LEVEL ecpg_into'; $replace_line{'VariableShowStmtSHOWSESSIONAUTHORIZATION'} = 'SHOW SESSION AUTHORIZATION ecpg_into'; +$replace_line{'returning_clauseRETURNINGtarget_list'} = 'RETURNING target_list ecpg_into'; $replace_line{'ExecuteStmtEXECUTEnameexecute_param_clause'} = 'EXECUTE prepared_name execute_param_clause execute_rest'; $replace_line{'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'} = 'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause'; $replace_line{'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'} = 'PREPARE prepared_name prep_type_clause AS PreparableStmt'; diff --git a/src/interfaces/ecpg/test/expected/sql-insupd.c b/src/interfaces/ecpg/test/expected/sql-insupd.c index 756f2b3c26..ab2f077bcc 100644 --- a/src/interfaces/ecpg/test/expected/sql-insupd.c +++ b/src/interfaces/ecpg/test/expected/sql-insupd.c @@ -24,10 +24,10 @@ int main() { /* exec sql begin declare section */ - + #line 9 "insupd.pgc" - int i1 [ 3 ] , i2 [ 3 ] ; + int i1 [ 3 ] , i2 [ 3 ] , i3 [ 3 ] , i4 ; /* exec sql end declare section */ #line 10 "insupd.pgc" @@ -72,7 +72,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint(); if (sqlca.sqlcode < 0) sqlprint();} #line 21 "insupd.pgc" - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into insupd_test ( a , b ) values ( 3 , 3 )", ECPGt_EOIT, ECPGt_EORT); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into insupd_test ( a , b ) values ( 3 , 3 ) returning a", ECPGt_EOIT, + ECPGt_int,&(i4),(long)1,(long)1,sizeof(int), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 22 "insupd.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); @@ -82,7 +84,9 @@ if (sqlca.sqlcode < 0) sqlprint();} #line 22 "insupd.pgc" - { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update insupd_test set a = a + 1", ECPGt_EOIT, ECPGt_EORT); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update insupd_test set a = a + 1 returning a", ECPGt_EOIT, + ECPGt_int,(i3),(long)1,(long)3,sizeof(int), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 24 "insupd.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); @@ -124,16 +128,17 @@ if (sqlca.sqlcode < 0) sqlprint();} #line 28 "insupd.pgc" + printf("changes\n%d %d %d %d\n", i3[0], i3[1], i3[2], i4); printf("test\na b\n%d %d\n%d %d\n%d %d\n", i1[0], i2[0], i1[1], i2[1], i1[2], i2[2]); { ECPGdisconnect(__LINE__, "ALL"); -#line 32 "insupd.pgc" +#line 33 "insupd.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 32 "insupd.pgc" +#line 33 "insupd.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 32 "insupd.pgc" +#line 33 "insupd.pgc" return 0; diff --git a/src/interfaces/ecpg/test/expected/sql-insupd.stderr b/src/interfaces/ecpg/test/expected/sql-insupd.stderr index be7ca27f8a..e01ed881b4 100644 --- a/src/interfaces/ecpg/test/expected/sql-insupd.stderr +++ b/src/interfaces/ecpg/test/expected/sql-insupd.stderr @@ -20,17 +20,25 @@ [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 21: OK: INSERT 0 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 22: query: insert into insupd_test ( a , b ) values ( 3 , 3 ); with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 22: query: insert into insupd_test ( a , b ) values ( 3 , 3 ) returning a; 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]: ecpg_execute on line 22: correctly got 1 tuples with 1 fields [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 24: query: update insupd_test set a = a + 1; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_get_data on line 22: RESULT: 3 offset: -1; array: no +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 24: query: update insupd_test set a = a + 1 returning a; 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: UPDATE 3 +[NO_PID]: ecpg_execute on line 24: correctly got 3 tuples with 1 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_get_data on line 24: RESULT: 2 offset: -1; array: no +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_get_data on line 24: RESULT: 3 offset: -1; array: no +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_get_data on line 24: RESULT: 4 offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 25: query: update insupd_test set ( a , b ) = ( 5 , 5 ) where a = 4; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/sql-insupd.stdout b/src/interfaces/ecpg/test/expected/sql-insupd.stdout index a861f3ea2d..5cefd43337 100644 --- a/src/interfaces/ecpg/test/expected/sql-insupd.stdout +++ b/src/interfaces/ecpg/test/expected/sql-insupd.stdout @@ -1,3 +1,5 @@ +changes +2 3 4 3 test a b 2 1 diff --git a/src/interfaces/ecpg/test/sql/insupd.pgc b/src/interfaces/ecpg/test/sql/insupd.pgc index 8a7b258072..4db1105eea 100644 --- a/src/interfaces/ecpg/test/sql/insupd.pgc +++ b/src/interfaces/ecpg/test/sql/insupd.pgc @@ -6,7 +6,7 @@ EXEC SQL INCLUDE ../regression; int main() { EXEC SQL BEGIN DECLARE SECTION; - int i1[3], i2[3]; + int i1[3], i2[3], i3[3], i4; EXEC SQL END DECLARE SECTION; ECPGdebug(1, stderr); @@ -19,14 +19,15 @@ int main() { EXEC SQL INSERT INTO insupd_test (a,b) values (1, 1); EXEC SQL INSERT INTO insupd_test (a,b) values (2, 2); - EXEC SQL INSERT INTO insupd_test (a,b) values (3, 3); + EXEC SQL INSERT INTO insupd_test (a,b) values (3, 3) returning a into :i4; - EXEC SQL UPDATE insupd_test set a=a+1; + EXEC SQL UPDATE insupd_test set a=a+1 returning a into :i3; EXEC SQL UPDATE insupd_test set (a,b)=(5,5) where a = 4; EXEC SQL UPDATE insupd_test set a=4 where a=3;; EXEC SQL SELECT a,b into :i1,:i2 from insupd_test order by a; + printf("changes\n%d %d %d %d\n", i3[0], i3[1], i3[2], i4); printf("test\na b\n%d %d\n%d %d\n%d %d\n", i1[0], i2[0], i1[1], i2[1], i1[2], i2[2]); EXEC SQL DISCONNECT ALL; -- 2.40.0