Let SQLExecute() destroy the old result first.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 14 Apr 2021 04:45:00 +0000 (13:45 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 21 Apr 2021 22:33:33 +0000 (07:33 +0900)
This change fixes the diff of insertreturning-test regression test
reported by Patrick Cheung.

execute.c
odbcapi.c
pgapifunc.h
statement.c

index 8ea02b91870cf77adcc1c74e22e896a89ca2c15f..6696ce62011a2976e5f0738aeacc6b899678831b 100644 (file)
--- 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 &&
index 2b4e5c63e3633bab46046d8a09290788f28a6ed3..9852d1bc962d12cde75fb11be677f81799a4cdc6 100644 (file)
--- 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);
    }
index 5c5b20dc163b199c85302c209e911ec00031298c..8c9599cd947f806617c539c77e235471b637fa8f 100644 (file)
@@ -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 */
index d79d323a2d9fa727ed43da7808cd79dde26ab8e4..972aa50f49484c540b7a2b48ad6f3fe99dd93f10 100644 (file)
@@ -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;