From 1ec4c56e76714d3894cfc301212ec98674720e3b Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Tue, 26 Nov 2013 17:15:15 +0100 Subject: [PATCH] ECPG: Add EXEC SQL CLOSE C to the tests. Patch by Boszormenyi Zoltan --- .../ecpg/test/expected/sql-binary.c | 22 +++++--- .../ecpg/test/expected/sql-binary.stderr | 56 ++++++++++--------- src/interfaces/ecpg/test/expected/sql-fetch.c | 46 +++++++++------ .../ecpg/test/expected/sql-fetch.stderr | 51 +++++++++-------- src/interfaces/ecpg/test/sql/binary.pgc | 2 + src/interfaces/ecpg/test/sql/fetch.pgc | 2 + 6 files changed, 103 insertions(+), 76 deletions(-) diff --git a/src/interfaces/ecpg/test/expected/sql-binary.c b/src/interfaces/ecpg/test/expected/sql-binary.c index 64497b6a72..9aa11d6cb1 100644 --- a/src/interfaces/ecpg/test/expected/sql-binary.c +++ b/src/interfaces/ecpg/test/expected/sql-binary.c @@ -133,15 +133,19 @@ main (void) printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);} +#line 69 "binary.pgc" + + memset(empl.name, 0, 21L); ECPGset_var( 1, &( empl.idnum ), __LINE__);\ /* declare B binary cursor for select name , accs , byte from empl where idnum = $1 */ -#line 70 "binary.pgc" +#line 72 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ", ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 71 "binary.pgc" +#line 73 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch B", ECPGt_EOIT, ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), @@ -150,7 +154,7 @@ main (void) ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 72 "binary.pgc" +#line 74 "binary.pgc" if (sqlca.sqlcode) { @@ -159,7 +163,7 @@ main (void) } { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);} -#line 79 "binary.pgc" +#line 81 "binary.pgc" /* do not print a.accs because big/little endian will have different outputs here */ @@ -170,17 +174,17 @@ main (void) ECPGset_var( 2, &( empl.idnum ), __LINE__);\ /* declare A binary cursor for select byte from empl where idnum = $1 */ -#line 87 "binary.pgc" +#line 89 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ", ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} -#line 88 "binary.pgc" +#line 90 "binary.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch A", ECPGt_EOIT, ECPGt_char,&(pointer),(long)0,(long)1,(1)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} -#line 89 "binary.pgc" +#line 91 "binary.pgc" if (sqlca.sqlcode) { @@ -189,7 +193,7 @@ main (void) } { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);} -#line 96 "binary.pgc" +#line 98 "binary.pgc" printf ("pointer="); @@ -199,7 +203,7 @@ main (void) free(pointer); { ECPGdisconnect(__LINE__, "CURRENT");} -#line 104 "binary.pgc" +#line 106 "binary.pgc" exit (0); } diff --git a/src/interfaces/ecpg/test/expected/sql-binary.stderr b/src/interfaces/ecpg/test/expected/sql-binary.stderr index e164a84177..d6b4777b4a 100644 --- a/src/interfaces/ecpg/test/expected/sql-binary.stderr +++ b/src/interfaces/ecpg/test/expected/sql-binary.stderr @@ -42,55 +42,61 @@ [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_get_data on line 60: RESULT: \001m\000\212 offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 71: query: declare B binary cursor for select name , accs , byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 69: query: close C; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 71: using PQexecParams +[NO_PID]: ecpg_execute on line 69: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: free_params on line 71: parameter 1 = 1 +[NO_PID]: ecpg_execute on line 69: OK: CLOSE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 71: OK: DECLARE CURSOR +[NO_PID]: ecpg_execute on line 73: query: declare B binary cursor for select name , accs , byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 72: query: fetch B; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 73: using PQexecParams [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 72: using PQexec +[NO_PID]: free_params on line 73: parameter 1 = 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 72: correctly got 1 tuples with 3 fields +[NO_PID]: ecpg_execute on line 73: OK: DECLARE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 72: RESULT: BINARY offset: -1; array: no +[NO_PID]: ecpg_execute on line 74: query: fetch B; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 72: RESULT: BINARY offset: -1; array: no +[NO_PID]: ecpg_execute on line 74: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 72: RESULT: BINARY offset: -1; array: no +[NO_PID]: ecpg_execute on line 74: correctly got 1 tuples with 3 fields [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 79: query: close B; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_get_data on line 74: RESULT: BINARY offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 79: using PQexec +[NO_PID]: ecpg_get_data on line 74: RESULT: BINARY offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 79: OK: CLOSE CURSOR +[NO_PID]: ecpg_get_data on line 74: RESULT: BINARY offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 88: query: declare A binary cursor for select byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 81: query: close B; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 88: using PQexecParams +[NO_PID]: ecpg_execute on line 81: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: free_params on line 88: parameter 1 = 1 +[NO_PID]: ecpg_execute on line 81: OK: CLOSE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 88: OK: DECLARE CURSOR +[NO_PID]: ecpg_execute on line 90: query: declare A binary cursor for select byte from empl where idnum = $1 ; with 1 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 89: query: fetch A; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 90: using PQexecParams [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 89: using PQexec +[NO_PID]: free_params on line 90: parameter 1 = 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 89: correctly got 1 tuples with 1 fields +[NO_PID]: ecpg_execute on line 90: OK: DECLARE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_store_result on line 89: allocating memory for 1 tuples +[NO_PID]: ecpg_execute on line 91: query: fetch A; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 89: RESULT: BINARY offset: -1; array: no +[NO_PID]: ecpg_execute on line 91: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 96: query: close A; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 91: correctly got 1 tuples with 1 fields [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 96: using PQexec +[NO_PID]: ecpg_store_result on line 91: allocating memory for 1 tuples [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 96: OK: CLOSE CURSOR +[NO_PID]: ecpg_get_data on line 91: RESULT: BINARY offset: -1; array: no +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 98: query: close A; with 0 parameter(s) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 98: using PQexec +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 98: OK: CLOSE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: connection regress1 closed [NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/expected/sql-fetch.c b/src/interfaces/ecpg/test/expected/sql-fetch.c index db7a0c2aab..c6be49ccb0 100644 --- a/src/interfaces/ecpg/test/expected/sql-fetch.c +++ b/src/interfaces/ecpg/test/expected/sql-fetch.c @@ -162,24 +162,34 @@ if (sqlca.sqlcode < 0) sqlprint();} printf("%d: %s\n", i, str); - /* declare D cursor for select * from My_Table where Item1 = $1 */ + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT); #line 42 "fetch.pgc" +if (sqlca.sqlwarn[0] == 'W') sqlprint(); +#line 42 "fetch.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 42 "fetch.pgc" + + + /* declare D cursor for select * from My_Table where Item1 = $1 */ +#line 44 "fetch.pgc" + { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare D cursor for select * from My_Table where Item1 = $1", ECPGt_const,"1",(long)1,(long)1,strlen("1"), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); -#line 44 "fetch.pgc" +#line 46 "fetch.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 44 "fetch.pgc" +#line 46 "fetch.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 44 "fetch.pgc" +#line 46 "fetch.pgc" /* exec sql whenever not found break ; */ -#line 46 "fetch.pgc" +#line 48 "fetch.pgc" while (1) { { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in D", ECPGt_EOIT, @@ -187,47 +197,47 @@ if (sqlca.sqlcode < 0) sqlprint();} ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); -#line 48 "fetch.pgc" +#line 50 "fetch.pgc" if (sqlca.sqlcode == ECPG_NOT_FOUND) break; -#line 48 "fetch.pgc" +#line 50 "fetch.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 48 "fetch.pgc" +#line 50 "fetch.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 48 "fetch.pgc" +#line 50 "fetch.pgc" printf("%d: %s\n", i, str); } { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close D", ECPGt_EOIT, ECPGt_EORT); -#line 51 "fetch.pgc" +#line 53 "fetch.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 51 "fetch.pgc" +#line 53 "fetch.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 51 "fetch.pgc" +#line 53 "fetch.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table My_Table", ECPGt_EOIT, ECPGt_EORT); -#line 53 "fetch.pgc" +#line 55 "fetch.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 53 "fetch.pgc" +#line 55 "fetch.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 53 "fetch.pgc" +#line 55 "fetch.pgc" { ECPGdisconnect(__LINE__, "ALL"); -#line 55 "fetch.pgc" +#line 57 "fetch.pgc" if (sqlca.sqlwarn[0] == 'W') sqlprint(); -#line 55 "fetch.pgc" +#line 57 "fetch.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 55 "fetch.pgc" +#line 57 "fetch.pgc" return 0; diff --git a/src/interfaces/ecpg/test/expected/sql-fetch.stderr b/src/interfaces/ecpg/test/expected/sql-fetch.stderr index 228421835d..246139bceb 100644 --- a/src/interfaces/ecpg/test/expected/sql-fetch.stderr +++ b/src/interfaces/ecpg/test/expected/sql-fetch.stderr @@ -102,46 +102,49 @@ [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_get_data on line 39: RESULT: text4 offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 44: query: declare D cursor for select * from My_Table where Item1 = $1; with 1 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 42: query: close C; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 44: using PQexecParams +[NO_PID]: ecpg_execute on line 42: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: free_params on line 44: parameter 1 = 1 +[NO_PID]: ecpg_execute on line 42: OK: CLOSE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 44: OK: DECLARE CURSOR +[NO_PID]: ecpg_execute on line 46: query: declare D cursor for select * from My_Table where Item1 = $1; with 1 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 48: query: fetch 1 in D; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 46: using PQexecParams [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 48: using PQexec +[NO_PID]: free_params on line 46: parameter 1 = 1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 48: correctly got 1 tuples with 2 fields +[NO_PID]: ecpg_execute on line 46: OK: DECLARE CURSOR [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 48: RESULT: 1 offset: -1; array: no +[NO_PID]: ecpg_execute on line 50: query: fetch 1 in D; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_get_data on line 48: RESULT: text1 offset: -1; array: no +[NO_PID]: ecpg_execute on line 50: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 48: query: fetch 1 in D; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 50: correctly got 1 tuples with 2 fields [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 48: using PQexec +[NO_PID]: ecpg_get_data on line 50: RESULT: 1 offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 48: correctly got 0 tuples with 2 fields +[NO_PID]: ecpg_get_data on line 50: RESULT: text1 offset: -1; array: no [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: raising sqlcode 100 on line 48: no data found on line 48 +[NO_PID]: ecpg_execute on line 50: query: fetch 1 in D; with 0 parameter(s) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 50: using PQexec +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 50: correctly got 0 tuples with 2 fields +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: raising sqlcode 100 on line 50: no data found on line 50 [NO_PID]: sqlca: code: 100, state: 02000 -[NO_PID]: ecpg_execute on line 51: query: close D; with 0 parameter(s) on connection regress1 -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 51: using PQexec -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 51: OK: CLOSE CURSOR -[NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_execute on line 53: query: drop table My_Table; with 0 parameter(s) on connection regress1 +[NO_PID]: ecpg_execute on line 53: query: close D; with 0 parameter(s) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_execute on line 53: using PQexec [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: ecpg_check_PQresult on line 53: bad response - ERROR: cannot DROP TABLE "my_table" because it is being used by active queries in this session +[NO_PID]: ecpg_execute on line 53: OK: CLOSE CURSOR +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 55: query: drop table My_Table; with 0 parameter(s) on connection regress1 +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 55: using PQexec +[NO_PID]: sqlca: code: 0, state: 00000 +[NO_PID]: ecpg_execute on line 55: OK: DROP TABLE [NO_PID]: sqlca: code: 0, state: 00000 -[NO_PID]: raising sqlstate 55006 (sqlcode -400): cannot DROP TABLE "my_table" because it is being used by active queries in this session on line 53 -[NO_PID]: sqlca: code: -400, state: 55006 -SQL error: cannot DROP TABLE "my_table" because it is being used by active queries in this session on line 53 [NO_PID]: ecpg_finish: connection regress1 closed [NO_PID]: sqlca: code: 0, state: 00000 diff --git a/src/interfaces/ecpg/test/sql/binary.pgc b/src/interfaces/ecpg/test/sql/binary.pgc index 723027d833..7cc77d2e32 100644 --- a/src/interfaces/ecpg/test/sql/binary.pgc +++ b/src/interfaces/ecpg/test/sql/binary.pgc @@ -66,6 +66,8 @@ main (void) printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte); + EXEC SQL CLOSE C; + memset(empl.name, 0, 21L); EXEC SQL DECLARE B BINARY CURSOR FOR select name, accs, byte from empl where idnum =:empl.idnum; EXEC SQL OPEN B; diff --git a/src/interfaces/ecpg/test/sql/fetch.pgc b/src/interfaces/ecpg/test/sql/fetch.pgc index e280d27f4e..aade678efb 100644 --- a/src/interfaces/ecpg/test/sql/fetch.pgc +++ b/src/interfaces/ecpg/test/sql/fetch.pgc @@ -39,6 +39,8 @@ int main() { EXEC SQL FETCH :count IN C INTO :i, :str; printf("%d: %s\n", i, str); + EXEC SQL CLOSE C; + EXEC SQL DECLARE D CURSOR FOR SELECT * FROM My_Table WHERE Item1 = $1; EXEC SQL OPEN D using 1;