From efc410ad11c38f0e759d976484771ea122f126d5 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Wed, 14 Apr 2021 13:45:00 +0900 Subject: [PATCH] Let SQLExecute() destroy the old result first. This change fixes the diff of insertreturning-test regression test reported by Patrick Cheung. --- execute.c | 7 ++++--- odbcapi.c | 3 ++- pgapifunc.h | 1 + statement.c | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/execute.c b/execute.c index 8ea02b9..6696ce6 100644 --- a/execute.c +++ b/execute.c @@ -934,7 +934,7 @@ PGAPI_Execute(HSTMT hstmt, UWORD flag) BOOL exec_end = FALSE, recycled = FALSE, recycle = TRUE; SQLSMALLINT num_params; - MYLOG(0, "entering...%x\n", flag); + MYLOG(0, "entering...%x %p status=%d\n", flag, stmt, stmt->status); stmt->has_notice = 0; conn = SC_get_conn(stmt); @@ -944,7 +944,8 @@ PGAPI_Execute(HSTMT hstmt, UWORD flag) * If the statement was previously described, just recycle the old result * set that contained just the column information. */ - if (stmt->prepare && stmt->status == STMT_DESCRIBED) + if ((stmt->prepare && stmt->status == STMT_DESCRIBED) || + (stmt->status == STMT_FINISHED && 0 != (flag & PODBC_RECYCLE_STATEMENT))) { stmt->exec_current_row = -1; SC_recycle_statement(stmt); @@ -1184,7 +1185,7 @@ next_param_row: goto next_param_row; } cleanup: -MYLOG(0, "leaving retval=%d\n", retval); +MYLOG(0, "leaving %p retval=%d status=%d\n", stmt, retval, stmt->status); SC_setInsertedTable(stmt, retval); #undef return if (SQL_SUCCESS == retval && diff --git a/odbcapi.c b/odbcapi.c index 2b4e5c6..9852d1b 100644 --- a/odbcapi.c +++ b/odbcapi.c @@ -341,13 +341,14 @@ SQLExecute(HSTMT StatementHandle) ENTER_STMT_CS(stmt); SC_clear_error(stmt); - flag |= PODBC_WITH_HOLD; + flag |= (PODBC_RECYCLE_STATEMENT | PODBC_WITH_HOLD); if (SC_opencheck(stmt, func)) ret = SQL_ERROR; else { StartRollbackState(stmt); stmt->exec_current_row = -1; + //// SC_set_Result(StatementHandle, NULL); ret = PGAPI_Execute(StatementHandle, flag); ret = DiscardStatementSvp(stmt, ret, FALSE); } diff --git a/pgapifunc.h b/pgapifunc.h index 5c5b20d..8c9599c 100644 --- a/pgapifunc.h +++ b/pgapifunc.h @@ -25,6 +25,7 @@ extern "C" { /* Internal flags for PGAPI_Exec... functions */ #define PODBC_WITH_HOLD 1L #define PODBC_RDONLY (1L << 1) +#define PODBC_RECYCLE_STATEMENT (1L << 2) /* Flags for the error handling */ #define PODBC_ALLOW_PARTIAL_EXTRACT 1L /* #define PODBC_ERROR_CLEAR (1L << 1) no longer used */ diff --git a/statement.c b/statement.c index d79d323..972aa50 100644 --- a/statement.c +++ b/statement.c @@ -2122,6 +2122,7 @@ SC_execute(StatementClass *self) if (CONN_DOWN != conn->status) conn->status = oldstatus; self->status = STMT_FINISHED; +MYLOG(0, "set %p STMT_FINISHED\n", self); LEAVE_INNER_CONN_CS(func_cs_count, conn); /* Check the status of the result */ @@ -3072,6 +3073,7 @@ BOOL SC_SetExecuting(StatementClass *self, BOOL on) { self->cancel_info = 0; self->status = STMT_FINISHED; +MYLOG(0, "set %p STMT_FINISHED\n", self); exeSet = TRUE; } LEAVE_COMMON_CS; -- 2.39.5