提交 d19669e5 编写于 作者: M Michael Meskes

Fixed auto-prepare to not try preparing statements that are not preparable. Bug

found and solved by Boszormenyi Zoltan <zb@cybertec.at>, some small adjustments
by me.
上级 dd4cd55c
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.11 2009/11/27 16:07:22 meskes Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.12 2009/12/16 10:15:06 meskes Exp $ */
ECPG: stmtClosePortalStmt block
{
if (INFORMIX_MODE)
......@@ -26,13 +26,14 @@ ECPG: stmtDeallocateStmt block
}
ECPG: stmtDeclareCursorStmt block
{ output_simple_statement($1); }
ECPG: stmtDeleteStmt block
ECPG: stmtDiscardStmt block
ECPG: stmtFetchStmt block
{ output_statement($1, 1, ECPGst_normal); }
ECPG: stmtDeleteStmt block
ECPG: stmtInsertStmt block
ECPG: stmtSelectStmt block
ECPG: stmtUpdateStmt block
{ output_statement($1, 1, ECPGst_normal); }
{ output_statement($1, 1, ECPGst_prepnormal); }
ECPG: stmtExecuteStmt block
{ output_statement($1, 1, ECPGst_execute); }
ECPG: stmtPrepareStmt block
......@@ -133,7 +134,7 @@ ECPG: stmtViewStmt rule
if ((ptr = add_additional_variables($1, true)) != NULL)
{
connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
output_statement(mm_strdup(ptr->command), 0, 0);
output_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
ptr->opened = true;
}
}
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.25 2009/06/11 14:49:13 momjian Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.26 2009/12/16 10:15:06 meskes Exp $ */
#include "postgres_fe.h"
......@@ -105,14 +105,24 @@ hashline_number(void)
return EMPTY;
}
static char *ecpg_statement_type_name[] = {
"ECPGst_normal",
"ECPGst_execute",
"ECPGst_exec_immediate",
"ECPGst_prepnormal"
};
void
output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
{
fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
if (st == ECPGst_normal)
if (st == ECPGst_execute || st == ECPGst_exec_immediate)
{
fprintf(yyout, "%s, %s, ", ecpg_statement_type_name[st], stmt);
}
else
{
if (auto_prepare)
if (st == ECPGst_prepnormal && auto_prepare)
fputs("ECPGst_prepnormal, \"", yyout);
else
fputs("ECPGst_normal, \"", yyout);
......@@ -120,8 +130,6 @@ output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
output_escaped_str(stmt, false);
fputs("\", ", yyout);
}
else
fprintf(yyout, "%d, %s, ", st, stmt);
/* dump variables to C file */
dump_variables(argsinsert, 1);
......
......@@ -26,118 +26,114 @@
int main() {
/* exec sql begin declare section */
#line 10 "autoprep.pgc"
int item [ 4 ] , ind [ 4 ] , i = 1 ;
/* exec sql end declare section */
#line 11 "autoprep.pgc"
int item1 , ind1 ;
#line 12 "autoprep.pgc"
char sqlstr [ 64 ] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST" ;
/* exec sql end declare section */
#line 13 "autoprep.pgc"
ECPGdebug(1, stderr);
{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
#line 14 "autoprep.pgc"
#line 16 "autoprep.pgc"
/* exec sql whenever sql_warning sqlprint ; */
#line 16 "autoprep.pgc"
#line 18 "autoprep.pgc"
/* exec sql whenever sqlerror sqlprint ; */
#line 17 "autoprep.pgc"
#line 19 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "create table T ( Item1 int , Item2 int )", ECPGt_EOIT, ECPGt_EORT);
#line 19 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table T ( Item1 int , Item2 int )", ECPGt_EOIT, ECPGt_EORT);
#line 21 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 19 "autoprep.pgc"
#line 21 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 19 "autoprep.pgc"
#line 21 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "insert into T values ( 1 , null )", ECPGt_EOIT, ECPGt_EORT);
#line 21 "autoprep.pgc"
#line 23 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 21 "autoprep.pgc"
#line 23 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 21 "autoprep.pgc"
#line 23 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "insert into T values ( 1 , $1 )",
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 22 "autoprep.pgc"
#line 24 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 22 "autoprep.pgc"
#line 24 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 22 "autoprep.pgc"
#line 24 "autoprep.pgc"
i++;
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "insert into T values ( 1 , $1 )",
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 24 "autoprep.pgc"
#line 26 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 24 "autoprep.pgc"
#line 26 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 24 "autoprep.pgc"
#line 26 "autoprep.pgc"
{ ECPGprepare(__LINE__, NULL, 0, "i", " insert into T values ( 1 , 2 ) ");
#line 25 "autoprep.pgc"
#line 27 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 25 "autoprep.pgc"
#line 27 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 25 "autoprep.pgc"
#line 27 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "i", ECPGt_EOIT, ECPGt_EORT);
#line 26 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i", ECPGt_EOIT, ECPGt_EORT);
#line 28 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 26 "autoprep.pgc"
#line 28 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 26 "autoprep.pgc"
#line 28 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "select Item2 from T order by Item2 nulls last", ECPGt_EOIT,
ECPGt_int,(item),(long)1,(long)4,sizeof(int),
ECPGt_int,(ind),(long)1,(long)4,sizeof(int), ECPGt_EORT);
#line 28 "autoprep.pgc"
#line 30 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 28 "autoprep.pgc"
#line 30 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 28 "autoprep.pgc"
#line 30 "autoprep.pgc"
for (i=0; i<4; i++)
printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
/* declare C cursor for select Item1 from T */
#line 33 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "declare C cursor for select Item1 from T", ECPGt_EOIT, ECPGt_EORT);
#line 35 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 35 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 35 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "fetch 1 in C", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select Item1 from T", ECPGt_EOIT, ECPGt_EORT);
#line 37 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
......@@ -146,19 +142,21 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
if (sqlca.sqlcode < 0) sqlprint();}
#line 37 "autoprep.pgc"
printf("i = %d\n", i);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "close C", ECPGt_EOIT, ECPGt_EORT);
#line 40 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 39 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 40 "autoprep.pgc"
#line 39 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 40 "autoprep.pgc"
#line 39 "autoprep.pgc"
printf("i = %d\n", i);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_prepnormal, "drop table T", ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
#line 42 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
......@@ -168,7 +166,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 42 "autoprep.pgc"
{ ECPGdisconnect(__LINE__, "ALL");
{ ECPGprepare(__LINE__, NULL, 0, "stmt1", sqlstr);
#line 44 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
......@@ -178,5 +176,76 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 44 "autoprep.pgc"
/* declare cur1 cursor for $1 */
#line 46 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for $1",
ECPGt_char_variable,(ECPGprepared_statement(NULL, "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 48 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 48 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 48 "autoprep.pgc"
/* exec sql whenever not found break ; */
#line 50 "autoprep.pgc"
i = 0;
while (1)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT,
ECPGt_int,&(item1),(long)1,(long)1,sizeof(int),
ECPGt_int,&(ind1),(long)1,(long)1,sizeof(int), ECPGt_EORT);
#line 55 "autoprep.pgc"
if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
#line 55 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 55 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 55 "autoprep.pgc"
printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
i++;
}
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
#line 60 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 60 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 60 "autoprep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table T", ECPGt_EOIT, ECPGt_EORT);
#line 62 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 62 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 62 "autoprep.pgc"
{ ECPGdisconnect(__LINE__, "ALL");
#line 64 "autoprep.pgc"
if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 64 "autoprep.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 64 "autoprep.pgc"
return 0;
}
......@@ -2,130 +2,156 @@
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT>
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 19: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 21: query: create table T ( Item1 int , Item2 int ); with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 19: name ecpg1; query: "create table T ( Item1 int , Item2 int )"
[NO_PID]: ecpg_execute on line 21: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 19: query: create table T ( Item1 int , Item2 int ); with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 21: OK: CREATE TABLE
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 19: using PQexecPrepared for "create table T ( Item1 int , Item2 int )"
[NO_PID]: ecpg_auto_prepare on line 23: statement not in cache; inserting
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 19: OK: CREATE TABLE
[NO_PID]: ECPGprepare on line 23: name ecpg1; query: "insert into T values ( 1 , null )"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 21: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 23: query: insert into T values ( 1 , null ); with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 21: name ecpg2; query: "insert into T values ( 1 , null )"
[NO_PID]: ecpg_execute on line 23: using PQexecPrepared for "insert into T values ( 1 , null )"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 21: query: insert into T values ( 1 , null ); with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 23: OK: INSERT 0 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 21: using PQexecPrepared for "insert into T values ( 1 , null )"
[NO_PID]: ecpg_auto_prepare on line 24: statement not in cache; inserting
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 21: OK: INSERT 0 1
[NO_PID]: ECPGprepare on line 24: name ecpg2; query: "insert into T values ( 1 , $1 )"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 22: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 24: query: insert into T values ( 1 , $1 ); with 1 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 22: name ecpg3; query: "insert into T values ( 1 , $1 )"
[NO_PID]: ecpg_execute on line 24: using PQexecPrepared for "insert into T values ( 1 , $1 )"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 22: query: insert into T values ( 1 , $1 ); with 1 parameter(s) on connection regress1
[NO_PID]: free_params on line 24: parameter 1 = 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 22: using PQexecPrepared for "insert into T values ( 1 , $1 )"
[NO_PID]: ecpg_execute on line 24: OK: INSERT 0 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: free_params on line 22: parameter 1 = 1
[NO_PID]: ecpg_auto_prepare on line 26: statement found in cache; entry 1640
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 22: OK: INSERT 0 1
[NO_PID]: ecpg_execute on line 26: query: insert into T values ( 1 , $1 ); with 1 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 24: statement found in cache; entry 1640
[NO_PID]: ecpg_execute on line 26: using PQexecPrepared for "insert into T values ( 1 , $1 )"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 24: query: insert into T values ( 1 , $1 ); with 1 parameter(s) on connection regress1
[NO_PID]: free_params on line 26: parameter 1 = 2
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 24: using PQexecPrepared for "insert into T values ( 1 , $1 )"
[NO_PID]: ecpg_execute on line 26: OK: INSERT 0 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: free_params on line 24: parameter 1 = 2
[NO_PID]: ECPGprepare on line 27: name i; query: " insert into T values ( 1 , 2 ) "
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 24: OK: INSERT 0 1
[NO_PID]: ecpg_execute on line 28: query: insert into T values ( 1 , 2 ) ; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 25: name i; query: " insert into T values ( 1 , 2 ) "
[NO_PID]: ecpg_execute on line 28: using PQexecPrepared for " insert into T values ( 1 , 2 ) "
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 26: query: insert into T values ( 1 , 2 ) ; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 28: OK: INSERT 0 1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 26: using PQexecPrepared for " insert into T values ( 1 , 2 ) "
[NO_PID]: ecpg_auto_prepare on line 30: statement not in cache; inserting
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 26: OK: INSERT 0 1
[NO_PID]: ECPGprepare on line 30: name ecpg3; query: "select Item2 from T order by Item2 nulls last"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 28: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 30: query: select Item2 from T order by Item2 nulls last; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 28: name ecpg4; query: "select Item2 from T order by Item2 nulls last"
[NO_PID]: ecpg_execute on line 30: using PQexecPrepared for "select Item2 from T order by Item2 nulls last"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 28: query: select Item2 from T order by Item2 nulls last; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 30: correctly got 4 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 28: using PQexecPrepared for "select Item2 from T order by Item2 nulls last"
[NO_PID]: ecpg_get_data on line 30: RESULT: 1 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 28: correctly got 4 tuples with 1 fields
[NO_PID]: ecpg_get_data on line 30: RESULT: 2 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 28: RESULT: 1 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 30: RESULT: 2 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 28: RESULT: 2 offset: -1; array: yes
[NO_PID]: ecpg_get_data on line 30: RESULT: offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 28: RESULT: 2 offset: -1; array: yes
[NO_PID]: ecpg_execute on line 37: query: declare C cursor for select Item1 from T; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 28: RESULT: offset: -1; array: yes
[NO_PID]: ecpg_execute on line 37: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 35: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 37: OK: DECLARE CURSOR
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 35: name ecpg5; query: "declare C cursor for select Item1 from T"
[NO_PID]: ecpg_execute on line 39: query: fetch 1 in C; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 35: query: declare C cursor for select Item1 from T; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 39: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 35: using PQexecPrepared for "declare C cursor for select Item1 from T"
[NO_PID]: ecpg_execute on line 39: correctly got 1 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 35: OK: DECLARE CURSOR
[NO_PID]: ecpg_get_data on line 39: RESULT: 1 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 37: statement not in cache; inserting
[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]: ECPGprepare on line 37: name ecpg6; query: "fetch 1 in C"
[NO_PID]: ecpg_execute on line 42: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 37: query: fetch 1 in C; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 42: OK: CLOSE CURSOR
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 37: using PQexecPrepared for "fetch 1 in C"
[NO_PID]: ECPGprepare on line 44: name stmt1; query: "SELECT item2 FROM T ORDER BY item2 NULLS LAST"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 37: correctly got 1 tuples with 1 fields
[NO_PID]: ecpg_execute on line 48: query: declare cur1 cursor for SELECT item2 FROM T ORDER BY item2 NULLS LAST; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 37: RESULT: 1 offset: -1; array: yes
[NO_PID]: ecpg_execute on line 48: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 40: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 48: OK: DECLARE CURSOR
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 40: name ecpg7; query: "close C"
[NO_PID]: ecpg_execute on line 55: query: fetch cur1; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 40: query: close C; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 55: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 40: using PQexecPrepared for "close C"
[NO_PID]: ecpg_execute on line 55: correctly got 1 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 40: OK: CLOSE CURSOR
[NO_PID]: ecpg_get_data on line 55: RESULT: 1 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_auto_prepare on line 42: statement not in cache; inserting
[NO_PID]: ecpg_execute on line 55: query: fetch cur1; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGprepare on line 42: name ecpg8; query: "drop table T"
[NO_PID]: ecpg_execute on line 55: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 42: query: drop table T; with 0 parameter(s) on connection regress1
[NO_PID]: ecpg_execute on line 55: correctly got 1 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 42: using PQexecPrepared for "drop table T"
[NO_PID]: ecpg_get_data on line 55: RESULT: 2 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 42: OK: DROP TABLE
[NO_PID]: ecpg_execute on line 55: query: fetch cur1; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg8
[NO_PID]: ecpg_execute on line 55: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg7
[NO_PID]: ecpg_execute on line 55: correctly got 1 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg6
[NO_PID]: ecpg_get_data on line 55: RESULT: 2 offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg5
[NO_PID]: ecpg_execute on line 55: query: fetch cur1; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg4
[NO_PID]: ecpg_execute on line 55: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name i
[NO_PID]: ecpg_execute on line 55: correctly got 1 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_get_data on line 55: RESULT: offset: -1; array: yes
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 55: query: fetch cur1; 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: correctly got 0 tuples with 1 fields
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: raising sqlcode 100 on line 55: no data found on line 55
[NO_PID]: sqlca: code: 100, state: 02000
[NO_PID]: ecpg_execute on line 60: query: close cur1; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 60: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 60: OK: CLOSE CURSOR
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 62: query: drop table T; with 0 parameter(s) on connection regress1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 62: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 62: OK: DROP TABLE
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name stmt1
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg3
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name i
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg2
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ECPGdeallocate on line 0: name ecpg1
......
......@@ -3,3 +3,7 @@ item[1] = 2
item[2] = 2
item[3] = -1
i = 1
item[0] = 1
item[1] = 2
item[2] = 2
item[3] = -1
......@@ -133,7 +133,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 33 "desc.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "foo1",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo1",
ECPGt_descriptor, "indesc", 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 35 "desc.pgc"
......@@ -160,7 +160,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 38 "desc.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "foo1",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo1",
ECPGt_descriptor, "indesc", 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 40 "desc.pgc"
......@@ -187,7 +187,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 43 "desc.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "Foo-1",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "Foo-1",
ECPGt_descriptor, "indesc", 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 45 "desc.pgc"
......@@ -221,7 +221,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
#line 50 "desc.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "foo2",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo2",
ECPGt_descriptor, "indesc", 0L, 0L, 0L,
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_descriptor, "outdesc", 0L, 0L, 0L,
......
......@@ -78,7 +78,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 29 "execute.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
......@@ -86,7 +86,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 32 "execute.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
......@@ -94,7 +94,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 35 "execute.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
......@@ -110,7 +110,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
if (sqlca.sqlcode < 0) sqlprint();}
#line 40 "execute.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "i",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
ECPGt_int,&(increment),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 41 "execute.pgc"
......@@ -268,7 +268,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
if (sqlca.sqlcode < 0) sqlprint();}
#line 93 "execute.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "f",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "f",
ECPGt_const,"2",(long)1,(long)1,strlen("2"),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
......
......@@ -78,7 +78,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
{ ECPGdo(__LINE__, 0, 1, NULL, 1, 2, command, ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 29 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
......@@ -86,7 +86,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
{ ECPGdo(__LINE__, 0, 1, NULL, 1, 2, command, ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 32 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
......@@ -94,7 +94,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
{ ECPGdo(__LINE__, 0, 1, NULL, 1, 2, command, ECPGt_EOIT, ECPGt_EORT);
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
#line 35 "oldexec.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
......@@ -110,7 +110,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
if (sqlca.sqlcode < 0) sqlprint();}
#line 40 "oldexec.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 1, 1, "i",
{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_execute, "i",
ECPGt_int,&(increment),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 41 "oldexec.pgc"
......
......@@ -167,7 +167,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
if (sqlca.sqlcode < 0) sqlprint();}
#line 51 "prep.pgc"
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "i",
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "i",
ECPGt_int,&(value),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 52 "prep.pgc"
......
......@@ -8,6 +8,8 @@ EXEC SQL INCLUDE ../regression;
int main() {
EXEC SQL BEGIN DECLARE SECTION;
int item[4], ind[4], i = 1;
int item1, ind1;
char sqlstr[64] = "SELECT item2 FROM T ORDER BY item2 NULLS LAST";
EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr);
......@@ -39,6 +41,24 @@ int main() {
EXEC SQL CLOSE C;
EXEC SQL PREPARE stmt1 FROM :sqlstr;
EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
EXEC SQL OPEN cur1;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
i = 0;
while (1)
{
EXEC SQL FETCH cur1 INTO :item1:ind1;
printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
i++;
}
EXEC SQL CLOSE cur1;
EXEC SQL DROP TABLE T;
EXEC SQL DISCONNECT ALL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册