Add test cases for:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 2 Dec 2014 11:15:57 +0000 (13:15 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 2 Dec 2014 12:34:33 +0000 (14:34 +0200)
* getting a bookmark with SQLBindCol,
* unbinding columns with SQLBindCol and SQLFreeStmt(SQL_UNBIND), and
* the procedure call "{ CALL ... }", and date, time, and timestamp escape
  syntaxes.

test/expected/bindcol.out
test/expected/bookmark.out
test/expected/odbc-escapes.out
test/src/bindcol-test.c
test/src/bookmark-test.c
test/src/odbc-escapes-test.c

index 8a6b9b07ee44ef0a15e9e063b530dc29a5b7aec6..9c15254390671eabec81daa63bca97cbf3b7042f 100644 (file)
@@ -1,7 +1,14 @@
 \! "./src/bindcol-test"
 connected
 Result set:
-1 foo
-2 bar
-3 foobar
+1 foo1
+2 foo2
+3 foo3
+4 foo3
+5 foo3
+6 foo6
+7 foo7
+7 foo7
+7 foo7
+7 foo10
 disconnecting
index 061d348cdcb92f5f30d19cadbb79e6a265c3e65f..7cd2a91a260f4714f20c50182f6857690cda3996 100644 (file)
@@ -17,4 +17,11 @@ Testing SQL_FETCH_BOOKMARK, middle (10)...
 fetched: foo111
 Testing SQL_FETCH_BOOKMARK, middle (-10)...
 fetched: foo91
+Getting bookmark with SQLBindCol...
+fetched: foo100
+Unbinding boomark column...
+Moving +100...
+fetched: foo200
+Goind back to bookmark acquired with SQLBindCol...
+fetched: foo100
 disconnecting
index 600ef0572365f5814f1bd764d1b62f99cb9c28cd..c32a02418fb924be9a881c087a9bedb1e3229925 100644 (file)
@@ -16,4 +16,27 @@ Result set:
 Query: SELECT 'x' || {fn SPACE(10) } || 'x'
 Result set:
 x          x
+
+Query: { call length(?) }
+Param 1: foobar
+Result set:
+6
+
+Query: { call right(?, ?) }
+Param 1: foobar
+Param 2: 3
+Result set:
+bar
+
+Query: SELECT {d '2014-12-21' } + '1 day'::interval
+Result set:
+2014-12-22 00:00:00
+
+Query: SELECT {t '20:30:40' } + '1 hour 1 minute 1 second'::interval
+Result set:
+21:31:41
+
+Query: SELECT {ts '2014-12-21 20:30:40' } + '1 day 1 hour 1 minute 1 second'::interval
+Result set:
+2014-12-22 21:31:41
 disconnecting
index 4d2dd0c9df818628330b15d526f37e41cfdff050..62326ed9a22216564625890055fff5b399c1ee7e 100644 (file)
@@ -6,8 +6,8 @@
 
 int main(int argc, char **argv)
 {
-   int rc;
-   HSTMT hstmt = SQL_NULL_HSTMT;
+   int         rc;
+   HSTMT       hstmt = SQL_NULL_HSTMT;
    /*
     * NOTE: in the psqlodbc, we assume that SQL_C_LONG actually means a
     * variable of type SQLINTEGER. They are not the same on platforms where
@@ -16,10 +16,11 @@ int main(int argc, char **argv)
     * (on little-endian systems, you won't notice the difference if you reset
     * the high bits to zero before calling SQLBindCol.)
     */
-   SQLINTEGER longvalue;
+   SQLINTEGER  longvalue;
    SQLLEN      indLongvalue;
-   char    charvalue[100];
-   SQLLEN  indCharvalue;
+   char        charvalue[100];
+   SQLLEN      indCharvalue;
+   int         rowno;
 
    test_connect();
 
@@ -36,10 +37,12 @@ int main(int argc, char **argv)
    rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, &charvalue, sizeof(charvalue), &indCharvalue);
    CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt);
 
-   rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT * FROM testtab1 ORDER BY id", SQL_NTS);
+   rc = SQLExecDirect(hstmt, (SQLCHAR *)
+                      "SELECT id, 'foo' || id FROM generate_series(1, 10) id", SQL_NTS);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
 
    printf("Result set:\n");
+   rowno = 0;
    while(1)
    {
        rc = SQLFetch(hstmt);
@@ -54,6 +57,28 @@ int main(int argc, char **argv)
            print_diag("SQLFetch failed", SQL_HANDLE_STMT, hstmt);
            exit(1);
        }
+
+       /*
+        * At row 3, unbind the text field. At row 5, bind it again.
+        * At row 7, unbind both columns with SQLFreeStmt(SQL_UNBIND).
+        * At row 9, bind text field again.
+        */
+       rowno++;
+       if (rowno == 3)
+       {
+           rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, NULL, 0, NULL);
+           CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt);
+       }
+       if (rowno == 7)
+       {
+           rc = SQLFreeStmt(hstmt, SQL_UNBIND);
+           CHECK_STMT_RESULT(rc, "SQLFreeStmt(SQL_UNBIND) failed", hstmt);
+       }
+       if (rowno == 5 || rowno == 9)
+       {
+           rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, &charvalue, sizeof(charvalue), &indCharvalue);
+           CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt);
+       }
    }
 
    rc = SQLFreeStmt(hstmt, SQL_CLOSE);
index 1f5543762fb8418b8f2f364c5046fb17d64f61fd..ccdfa5e8428900bae4264c581774a8c6c2d34b80 100644 (file)
@@ -103,6 +103,30 @@ testBookmarks(HSTMT hstmt)
    rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, -10);
    printFetchResult(hstmt, rc);
 
+   /*** Test getting a bookmark with SQLBindCol */
+   printf("Getting bookmark with SQLBindCol...\n");
+   rc = SQLBindCol(hstmt, 0, SQL_C_VARBOOKMARK, book_middle, sizeof(book_middle), &book_middle_ind);
+   CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt);
+
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 100);
+   printFetchResult(hstmt, rc);
+
+   printf("Unbinding boomark column...\n");
+   rc = SQLBindCol(hstmt, 0, SQL_C_VARBOOKMARK, NULL, 0, NULL);
+   CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt);
+
+   printf("Moving +100...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 100);
+   printFetchResult(hstmt, rc);
+
+   printf("Goind back to bookmark acquired with SQLBindCol...\n");
+   rc = SQLSetStmtAttr(hstmt, SQL_ATTR_FETCH_BOOKMARK_PTR,
+                       (SQLPOINTER) book_middle, SQL_IS_POINTER);
+   CHECK_STMT_RESULT(rc, "SQLSetStmtAttr failed", hstmt);
+
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, 0);
+   printFetchResult(hstmt, rc);
+
    rc = SQLFreeStmt(hstmt, SQL_CLOSE);
    CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
 }
index 75a00c6b001f098bff56dfabf9b16023a21890a2..0e479e4a22417e9f1421fe6e12a3cc561faf1d55 100644 (file)
@@ -82,6 +82,32 @@ int main(int argc, char **argv)
    prepareQuery(hstmt, "SELECT 'x' || {fn SPACE(10) } || 'x'");
    executeQuery(hstmt);
 
+   /**** CALL escapes ****/
+
+   prepareQuery(hstmt, "{ call length(?) }");
+   bindParamString(hstmt, 1, "foobar");
+   executeQuery(hstmt);
+
+   prepareQuery(hstmt, "{ call right(?, ?) }");
+   bindParamString(hstmt, 1, "foobar");
+   bindParamString(hstmt, 2, "3");
+   executeQuery(hstmt);
+
+   /* TODO: This doesn't currently work.
+   prepareQuery(hstmt, "{ ? = call concat(?, ?) }");
+   */
+
+   /**** Date, Time, and Timestamp literals ****/
+
+   prepareQuery(hstmt, "SELECT {d '2014-12-21' } + '1 day'::interval");
+   executeQuery(hstmt);
+
+   prepareQuery(hstmt, "SELECT {t '20:30:40' } + '1 hour 1 minute 1 second'::interval");
+   executeQuery(hstmt);
+
+   prepareQuery(hstmt, "SELECT {ts '2014-12-21 20:30:40' } + '1 day 1 hour 1 minute 1 second'::interval");
+   executeQuery(hstmt);
+
    /* Clean up */
    test_disconnect();