Add a *update returning* test case to insertreturning regression test.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Mon, 19 Apr 2021 06:25:41 +0000 (15:25 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 21 Apr 2021 10:54:16 +0000 (19:54 +0900)
The diff of the result was reported by Patrick Cheung and will be fixed
in the later commit.

test/expected/insertreturning.out
test/src/insertreturning-test.c

index 4e59a9d19fb8770472778ec6787df5b4fcb15007..2b80c4b569a2e966dd3ff9580bbc994d7053f41f 100644 (file)
@@ -300,6 +300,10 @@ foobar 98
 # of result cols before SQLExecute: 1, after: 1
 Result set:
 foobar 99
+SQLExecute UPDATE not found key i=0
+SQLExecute UPDATE not found key i=1
+SQLExecute UPDATE not found key i=2
+SQLExecute UPDATE key i=3 value t=foobar 3
 disconnecting
 Testing with UseServerSidePrepare=0
 connected
@@ -603,4 +607,8 @@ foobar 98
 # of result cols before SQLExecute: 1, after: 1
 Result set:
 foobar 99
+SQLExecute UPDATE not found key i=0
+SQLExecute UPDATE not found key i=1
+SQLExecute UPDATE not found key i=2
+SQLExecute UPDATE key i=3 value t=foobar 3
 disconnecting
index 0914e57aa7993fcaeaaa3ff6c61c1c4c70f7cd00..f51a08a82f9670d6e9876a04f0d0594525233b64 100644 (file)
@@ -35,6 +35,7 @@ run_test()
    SQLRETURN rc;
    HSTMT hstmt = SQL_NULL_HSTMT;
    char param1[100];
+   int param2;
    SQLLEN cbParam1;
    SQLSMALLINT colcount1, colcount2;
    SQLCHAR *sql;
@@ -97,6 +98,56 @@ run_test()
        CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
    }
 
+   /* Test for UPDATE returning */
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "TRUNCATE TABLE tmptable", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed while truncating temp table", hstmt);
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "INSERT INTO tmptable values(3,'foo')", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed while nserting temp table", hstmt);
+   /* Prepare a UPDATE statement */
+   rc = SQLPrepare(hstmt, (SQLCHAR *) "UPDATE tmptable set t=? where i=? RETURNING (t)", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLPrepare for UPDATE failed", hstmt);
+   /* bind params  */
+   rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
+                         SQL_C_CHAR,   /* value type */
+                         SQL_CHAR, /* param type */
+                         20,       /* column size */
+                         0,        /* dec digits */
+                         param1,       /* param value ptr */
+                         0,        /* buffer len */
+                         &cbParam1 /* StrLen_or_IndPtr */);
+   CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt);
+   rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT,
+                         SQL_C_SLONG,  /* value type */
+                         SQL_INTEGER,  /* param type */
+                         0,        /* column size */
+                         0,        /* dec digits */
+                         &param2,  /* param value ptr */
+                         0,        /* buffer len */
+                         NULL      /* StrLen_or_IndPtr */);
+   CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt);
+   for (i = 0; i < 4;i++)
+   {
+       snprintf(param1, sizeof(param1), "foobar %d", i);
+       cbParam1 = SQL_NTS;
+       param2 = i;
+       rc = SQLExecute(hstmt);
+       if (SQL_SUCCEEDED(rc))
+       {
+           rc = SQLFetch(hstmt);
+           if (SQL_NO_DATA == rc)
+               printf("??? SQLFetch for UPDATE not found key i=%d\n", param2);
+           else if (SQL_SUCCEEDED(rc))
+               printf("SQLExecute UPDATE key i=%d value t=%s\n", param2, param1);
+           else
+               CHECK_STMT_RESULT(rc, "SQLFetch for UPDATE failed", hstmt);
+           SQLFreeStmt(hstmt, SQL_CLOSE);
+       }
+       else if (SQL_NO_DATA == rc)
+           printf("SQLExecute UPDATE not found key i=%d\n", param2);
+       else
+           CHECK_STMT_RESULT(rc, "SQLExecute UPDATE failed", hstmt);
+   }
+
    rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
    if (!SQL_SUCCEEDED(rc))
    {