diff options
author | Michael Meskes <meskes@postgresql.org> | 2021-08-13 10:34:04 +0200 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2021-08-13 10:45:08 +0200 |
commit | 399edafa2aba562a8013fbe039f3cbf3a41a436e (patch) | |
tree | ab6b4389af421ea0982fa1da9c7d9f92dade93d6 /src/interfaces/ecpg/test/expected/sql-declare.c | |
parent | 512f4ca6c6b5d2e3a1620288048ccaa712121e12 (diff) | |
download | postgresql-399edafa2aba562a8013fbe039f3cbf3a41a436e.tar.gz postgresql-399edafa2aba562a8013fbe039f3cbf3a41a436e.zip |
Fix connection handling for DEALLOCATE and DESCRIBE statements
After binding a statement to a connection with DECLARE STATEMENT the connection
was still not used for DEALLOCATE and DESCRIBE statements. This patch fixes
that, adds a missing warning and cleans up the code.
Author: Hayato Kuroda
Reviewed-by: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/TYAPR01MB5866BA57688DF2770E2F95C6F5069%40TYAPR01MB5866.jpnprd01.prod.outlook.com
Diffstat (limited to 'src/interfaces/ecpg/test/expected/sql-declare.c')
-rw-r--r-- | src/interfaces/ecpg/test/expected/sql-declare.c | 137 |
1 files changed, 122 insertions, 15 deletions
diff --git a/src/interfaces/ecpg/test/expected/sql-declare.c b/src/interfaces/ecpg/test/expected/sql-declare.c index 7ca540df28d..cff928204e5 100644 --- a/src/interfaces/ecpg/test/expected/sql-declare.c +++ b/src/interfaces/ecpg/test/expected/sql-declare.c @@ -97,7 +97,7 @@ struct sqlca_t *ECPGget_sqlca(void); #line 8 "declare.pgc" -#define ARRAY_SZIE 20 +#define ARRAY_SIZE 2 void execute_test(void); void commitTable(void); @@ -110,13 +110,13 @@ void printResult(char *tc_name, int loop); #line 18 "declare.pgc" - int f1 [ ARRAY_SZIE ] ; + int f1 [ ARRAY_SIZE ] ; #line 19 "declare.pgc" - int f2 [ ARRAY_SZIE ] ; + int f2 [ ARRAY_SIZE ] ; #line 20 "declare.pgc" - char f3 [ ARRAY_SZIE ] [ 20 ] ; + char f3 [ ARRAY_SIZE ] [ 20 ] ; /* exec sql end declare section */ #line 21 "declare.pgc" @@ -216,11 +216,11 @@ if (sqlca.sqlcode < 0) sqlprint();} void execute_test(void) { /* exec sql begin declare section */ - + #line 63 "declare.pgc" - int i ; + int i , count , length ; #line 64 "declare.pgc" char * selectString = "SELECT f1,f2,f3 FROM source" ; @@ -353,7 +353,7 @@ if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();} #line 110 "declare.pgc" - { ECPGdeallocate(__LINE__, 0, NULL, "stmt_2"); + { ECPGdeallocate(__LINE__, 0, "con1", "stmt_2"); #line 111 "declare.pgc" if (sqlca.sqlcode < 0) sqlprint();} @@ -421,7 +421,7 @@ if (sqlca.sqlcode < 0) sqlprint();} if (sqlca.sqlcode < 0) sqlprint();} #line 134 "declare.pgc" - { ECPGdeallocate(__LINE__, 0, "con2", "stmt_3"); + { ECPGdeallocate(__LINE__, 0, "con1", "stmt_3"); #line 135 "declare.pgc" if (sqlca.sqlcode < 0) sqlprint();} @@ -518,11 +518,11 @@ if (sqlca.sqlcode < 0) sqlprint();} #line 172 "declare.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "stmt_5", ECPGt_EOIT, - ECPGt_int,(f1),(long)1,(long)ARRAY_SZIE,sizeof(int), + ECPGt_int,(f1),(long)1,(long)ARRAY_SIZE,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_int,(f2),(long)1,(long)ARRAY_SZIE,sizeof(int), + ECPGt_int,(f2),(long)1,(long)ARRAY_SIZE,sizeof(int), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, - ECPGt_char,(f3),(long)20,(long)ARRAY_SZIE,(20)*sizeof(char), + ECPGt_char,(f3),(long)20,(long)ARRAY_SIZE,(20)*sizeof(char), ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); #line 173 "declare.pgc" @@ -538,21 +538,128 @@ if (sqlca.sqlcode < 0) sqlprint();} printResult("testcase5", 2); + + /* + * DESCRIBE statement is also supported. + */ + /* declare \"stmt_desc\" as an SQL identifier */ +#line 182 "declare.pgc" + + { ECPGprepare(__LINE__, "con1", 0, "stmt_desc", selectString); +#line 183 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 183 "declare.pgc" + + /* declare cur_desc cursor for $1 */ +#line 184 "declare.pgc" + + { ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "declare cur_desc cursor for $1", + ECPGt_char_variable,(ECPGprepared_statement("con1", "stmt_desc", __LINE__)),(long)1,(long)1,(1)*sizeof(char), + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT); +#line 185 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 185 "declare.pgc" + + + /* descriptor can be used for describe statement */ + ECPGallocate_desc(__LINE__, "desc_for_describe"); +#line 188 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint(); +#line 188 "declare.pgc" + + { ECPGdescribe(__LINE__, 0, 0, "con1", "stmt_desc", + ECPGt_descriptor, "desc_for_describe", 1L, 1L, 1L, + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} +#line 189 "declare.pgc" + + + { ECPGget_desc_header(__LINE__, "desc_for_describe", &(count)); + +#line 191 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 191 "declare.pgc" + + { ECPGget_desc(__LINE__, "desc_for_describe", 3,ECPGd_length, + ECPGt_int,&(length),(long)1,(long)1,sizeof(int), ECPGd_EODT); + +#line 192 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 192 "declare.pgc" + + + ECPGdeallocate_desc(__LINE__, "desc_for_describe"); +#line 194 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint(); +#line 194 "declare.pgc" + + + /* for fetch statement */ + ECPGallocate_desc(__LINE__, "desc_for_fetch"); +#line 197 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint(); +#line 197 "declare.pgc" + + { ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "fetch cur_desc", ECPGt_EOIT, + ECPGt_descriptor, "desc_for_fetch", 1L, 1L, 1L, + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); +#line 198 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 198 "declare.pgc" + + + { ECPGget_desc(__LINE__, "desc_for_fetch", 3,ECPGd_data, + ECPGt_char,(f3[0]),(long)20,(long)1,(20)*sizeof(char), ECPGd_EODT); + +#line 200 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 200 "declare.pgc" + + + ECPGdeallocate_desc(__LINE__, "desc_for_fetch"); +#line 202 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint(); +#line 202 "declare.pgc" + + { ECPGdo(__LINE__, 0, 1, "con1", 0, ECPGst_normal, "close cur_desc", ECPGt_EOIT, ECPGt_EORT); +#line 203 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 203 "declare.pgc" + + { ECPGdeallocate(__LINE__, 0, "con1", "stmt_desc"); +#line 204 "declare.pgc" + +if (sqlca.sqlcode < 0) sqlprint();} +#line 204 "declare.pgc" + + + printf("****descriptor results****\n"); + printf("count: %d, length: %d, data: %s\n", count, length, f3[0]); } void commitTable() { { ECPGtrans(__LINE__, "con1", "commit"); -#line 182 "declare.pgc" +#line 212 "declare.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 182 "declare.pgc" +#line 212 "declare.pgc" { ECPGtrans(__LINE__, "con2", "commit"); -#line 183 "declare.pgc" +#line 213 "declare.pgc" if (sqlca.sqlcode < 0) sqlprint();} -#line 183 "declare.pgc" +#line 213 "declare.pgc" } |