Add more test cases.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 26 Nov 2014 12:50:45 +0000 (14:50 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 26 Nov 2014 13:40:30 +0000 (15:40 +0200)
This adds coverage for SQLConnect, SQLRowCount, and moving a cursor with
SQLFetchScroll, and for bookmarks.

12 files changed:
Makefile.am
test/expected/bookmark.out [new file with mode: 0644]
test/expected/connect.out
test/expected/cursor-movement.out [new file with mode: 0644]
test/expected/update.out [new file with mode: 0644]
test/src/bookmark-test.c [new file with mode: 0644]
test/src/common.c
test/src/connect-test.c
test/src/cursor-movement-test.c [new file with mode: 0644]
test/src/cursors-test.c
test/src/update-test.c [new file with mode: 0644]
test/tests

index 55da59cdeb10e72edd6530bd6ce50f9fe2e1ac31..797bee4db5b957a235e6df08d4799f3199fa35d7 100644 (file)
@@ -90,12 +90,14 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
    test/expected/alter.out \
    test/expected/arraybinding.out \
    test/expected/bindcol.out \
+   test/expected/bookmark.out \
    test/expected/boolsaschar.out \
    test/expected/catalogfunctions.out \
    test/expected/commands.out \
    test/expected/connect.out \
    test/expected/cte.out \
    test/expected/cursor-commit.out \
+   test/expected/cursor-movement.out \
    test/expected/declare-fetch-commit-test.out \
    test/expected/cursors.out \
    test/expected/cursors_1.out \
@@ -120,6 +122,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
    test/expected/sampletables.out \
    test/expected/select.out \
    test/expected/stmthandles.out \
+   test/expected/update.out \
    test/launcher \
    test/Makefile.in \
    test/odbc.ini \
@@ -129,6 +132,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
    test/src/alter-test.c \
    test/src/arraybinding-test.c \
    test/src/bindcol-test.c \
+   test/src/bookmark-test.c \
    test/src/boolsaschar-test.c \
    test/src/catalogfunctions-test.c \
    test/src/commands-test.c \
@@ -137,6 +141,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
    test/src/connect-test.c \
    test/src/cte-test.c \
    test/src/cursor-commit-test.c \
+   test/src/cursor-movement-test.c \
    test/src/declare-fetch-commit-test.c \
    test/src/cursors-test.c \
    test/src/cvtnulldate-test.c \
@@ -159,6 +164,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
    test/src/result-conversions-test.c \
    test/src/select-test.c \
    test/src/stmthandles-test.c \
+   test/src/update-test.c \
    test/tests \
    test/win.mak
 
diff --git a/test/expected/bookmark.out b/test/expected/bookmark.out
new file mode 100644 (file)
index 0000000..061d348
--- /dev/null
@@ -0,0 +1,20 @@
+\! "./src/bookmark-test"
+connected
+Getting bookmark to beginning of result set...
+fetched: foo1
+Moving +100...
+fetched: foo101
+Getting bookmark to middle of result set...
+Moving +100...
+fetched: foo201
+Testing SQL_FETCH_BOOKMARK, begin (0)...
+fetched: foo1
+Testing SQL_FETCH_BOOKMARK, begin (10)...
+fetched: foo11
+Testing SQL_FETCH_BOOKMARK, middle (0)...
+fetched: foo101
+Testing SQL_FETCH_BOOKMARK, middle (10)...
+fetched: foo111
+Testing SQL_FETCH_BOOKMARK, middle (-10)...
+fetched: foo91
+disconnecting
index 100e704d5842d07b628e3b1c9537e3b42bf81ba8..51b460d2dc5972c772428e2cff2738298c627758 100644 (file)
@@ -1,3 +1,5 @@
 \! "./src/connect-test"
 connected
 disconnecting
+Connecting with SQLConnect...connected
+disconnecting
diff --git a/test/expected/cursor-movement.out b/test/expected/cursor-movement.out
new file mode 100644 (file)
index 0000000..13b0f20
--- /dev/null
@@ -0,0 +1,58 @@
+\! "./src/cursor-movement-test"
+connected
+SQL_CURSOR_COMMIT_BEHAVIOR: SQL_CB_PRESERVE
+SQL_CURSOR_ROLLBACK_BEHAVIOR: SQL_CB_PRESERVE
+
+fetched: foo1
+fetched: foo2
+fetched: foo3
+fetched: foo4
+fetched: foo5
+fetched: foo6
+fetched: foo7
+fetched: foo8
+fetched: foo9
+fetched: foo10
+Testing SQL_FETCH_NEXT...
+fetched: foo11
+fetched: foo12
+Testing SQL_FETCH_PRIOR...
+fetched: foo11
+Testing SQL_FETCH_ABSOLUTE (5)...
+fetched: foo5
+Testing SQL_FETCH_RELATIVE (+2)...
+fetched: foo7
+Testing SQL_FETCH_RELATIVE (-2)...
+fetched: foo5
+Testing SQL_FETCH_RELATIVE (+1)...
+fetched: foo6
+Testing SQL_FETCH_RELATIVE (0, no movement)...
+fetched: foo6
+Testing SQL_FETCH_FIRST...
+fetched: foo1
+Testing SQL_FETCH_PRIOR before first row...
+Fetch: no data found
+Fetch: no data found
+Testing SQL_FETCH_NEXT...
+fetched: foo1
+Testing SQL_FETCH_LAST...
+fetched: foo3210
+Testing SQL_FETCH_LAST...
+fetched: foo3210
+Testing SQL_FETCH_NEXT at the end of result set
+Fetch: no data found
+Testing SQL_FETCH_NEXT at the end of result set
+Fetch: no data found
+And SQL_FETCH_PRIOR...
+fetched: foo3210
+Testing SQL_FETCH_RELATIVE (+10)...
+Fetch: no data found
+And SQL_FETCH_PRIOR...
+fetched: foo3210
+Testing negative SQL_FETCH_ABSOLUTE (-5)...
+fetched: foo3206
+Testing negative SQL_FETCH_ABSOLUTE, before start...
+Fetch: no data found
+Testing  SQL_FETCH_ABSOLUTE, beoynd end...
+Fetch: no data found
+disconnecting
diff --git a/test/expected/update.out b/test/expected/update.out
new file mode 100644 (file)
index 0000000..8ff0808
--- /dev/null
@@ -0,0 +1,14 @@
+\! "./src/update-test"
+connected
+# of rows inserted: 1
+# of rows inserted: 1
+# of rows inserted: 1
+# of rows inserted: 1
+# of rows inserted: 1
+# of rows updated: 3
+# of rows deleted: 2
+Result set:
+5  foobar
+1  updated 1
+3  updated 3
+disconnecting
diff --git a/test/src/bookmark-test.c b/test/src/bookmark-test.c
new file mode 100644 (file)
index 0000000..ceac8d9
--- /dev/null
@@ -0,0 +1,131 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+static void
+printFetchResult(HSTMT hstmt, int rc)
+{
+   if (SQL_SUCCEEDED(rc))
+   {
+       char buf[40];
+       SQLLEN ind;
+
+       if (rc == SQL_SUCCESS_WITH_INFO)
+           print_diag("got SUCCESS_WITH_INFO", SQL_HANDLE_STMT, hstmt);
+
+       rc = SQLGetData(hstmt, 1, SQL_C_CHAR, buf, sizeof(buf), &ind);
+       CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt);
+       printf("fetched: %s\n", buf);
+   }
+   else if (rc == SQL_NO_DATA)
+       printf("Fetch: no data found\n"); /* expected */
+   else
+       CHECK_STMT_RESULT(rc, "Fetch failed", hstmt);
+}
+
+static void
+testBookmarks(HSTMT hstmt)
+{
+   char        book_before[100];
+   SQLLEN      book_before_ind;
+   char        book_middle[100];
+   SQLLEN      book_middle_ind;
+   int rc;
+
+   /* Make the cursor scrollable */
+   rc = SQLSetStmtAttr(hstmt, SQL_CURSOR_TYPE,
+                       (SQLPOINTER) SQL_CURSOR_STATIC, SQL_IS_UINTEGER);
+   CHECK_STMT_RESULT(rc, "SQLSetStmtAttr failed", hstmt);
+
+   /* Enable bookmarks */
+   rc = SQLSetStmtAttr(hstmt, SQL_ATTR_USE_BOOKMARKS,
+                       (SQLPOINTER) SQL_UB_VARIABLE, SQL_IS_UINTEGER);
+   CHECK_STMT_RESULT(rc, "SQLSetStmtAttr failed", hstmt);
+
+   /*
+    * Fetch a large result set.
+    */
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT 'foo' || g FROM generate_series(1, 3210) g", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+
+   /* Get a bookmark that points to the beginning of the result set */
+   printf("Getting bookmark to beginning of result set...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
+   printFetchResult(hstmt, rc);
+
+   rc = SQLGetData(hstmt, 0, SQL_C_VARBOOKMARK, book_before, sizeof(book_before), &book_before_ind);
+   CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt);
+
+   printf("Moving +100...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 100);
+   printFetchResult(hstmt, rc);
+
+   /* Get a bookmark that points to the middle of the result set */
+   printf("Getting bookmark to middle of result set...\n");
+   rc = SQLGetData(hstmt, 0, SQL_C_VARBOOKMARK, book_middle, sizeof(book_middle), &book_middle_ind);
+   CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt);
+
+   /*** Ok, test SQLFetchScroll with the bookmark ***/
+
+   printf("Moving +100...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 100);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_BOOKMARK, begin (0)...\n");
+   rc = SQLSetStmtAttr(hstmt, SQL_ATTR_FETCH_BOOKMARK_PTR,
+                       (SQLPOINTER) book_before, SQL_IS_POINTER);
+   CHECK_STMT_RESULT(rc, "SQLSetStmtAttr failed", hstmt);
+
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_BOOKMARK, begin (10)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, 10);
+   printFetchResult(hstmt, rc);
+
+   /*** Test SQLFetchScroll with the middle bookmark ***/
+
+   printf("Testing SQL_FETCH_BOOKMARK, middle (0)...\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);
+
+   printf("Testing SQL_FETCH_BOOKMARK, middle (10)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, 10);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_BOOKMARK, middle (-10)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, -10);
+   printFetchResult(hstmt, rc);
+
+   rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+   CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+}
+
+int main(int argc, char **argv)
+{
+   int rc;
+   HSTMT hstmt = SQL_NULL_HSTMT;
+   SQLUSMALLINT info;
+
+   test_connect();
+
+   rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
+   if (!SQL_SUCCEEDED(rc))
+   {
+       print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
+       exit(1);
+   }
+
+   testBookmarks(hstmt);
+
+   /* Clean up */
+   test_disconnect();
+
+   return 0;
+}
index 646ea71f2068ed84872bebc9630027e3b69f9e21..275f5d9eda03cd3e096366c62c26c0847835f21c 100644 (file)
@@ -19,6 +19,8 @@ print_diag(char *msg, SQLSMALLINT htype, SQLHANDLE handle)
                        message, 256, &textlen);
    if (ret == SQL_INVALID_HANDLE)
        printf("Invalid handle\n");
+   if (ret == SQL_NO_DATA)
+       printf("No error information\n");
    else if (ret != SQL_ERROR)
        printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message);
 }
index 74c8b3be9959756840aa060f80757d51cdf045e9..89c0197d63cba4312c12df782ed31d3eae18b2ca 100644 (file)
@@ -3,10 +3,37 @@
 
 #include "common.h"
 
+static void
+test_SQLConnect()
+{
+   SQLRETURN ret;
+   SQLCHAR *dsn = (SQLCHAR *) "psqlodbc_test_dsn";
+
+   SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
+
+   SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
+
+   SQLAllocHandle(SQL_HANDLE_DBC, env, &conn);
+
+   printf("Connecting with SQLConnect...");
+
+   ret = SQLConnect(conn, dsn, SQL_NTS, NULL, 0, NULL, 0);
+   if (SQL_SUCCEEDED(ret)) {
+       printf("connected\n");
+   } else {
+       print_diag("SQLDriverConnect failed.", SQL_HANDLE_DBC, conn);
+       exit(1);
+   }
+}
+
 int main(int argc, char **argv)
 {
+   /* the common test_connect() function uses SQLDriverConnect */
    test_connect();
    test_disconnect();
 
+   test_SQLConnect();
+   test_disconnect();
+
    return 0;
 }
diff --git a/test/src/cursor-movement-test.c b/test/src/cursor-movement-test.c
new file mode 100644 (file)
index 0000000..ff81907
--- /dev/null
@@ -0,0 +1,205 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+static void
+printFetchResult(HSTMT hstmt, int rc)
+{
+   if (SQL_SUCCEEDED(rc))
+   {
+       char buf[40];
+       SQLLEN ind;
+
+       if (rc == SQL_SUCCESS_WITH_INFO)
+           print_diag("got SUCCESS_WITH_INFO", SQL_HANDLE_STMT, hstmt);
+
+       rc = SQLGetData(hstmt, 1, SQL_C_CHAR, buf, sizeof(buf), &ind);
+       CHECK_STMT_RESULT(rc, "SQLGetData failed", hstmt);
+       printf("fetched: %s\n", buf);
+   }
+   else if (rc == SQL_NO_DATA)
+       printf("Fetch: no data found\n"); /* expected */
+   else
+       CHECK_STMT_RESULT(rc, "Fetch failed", hstmt);
+}
+
+static void
+testLargeResult(HSTMT hstmt)
+{
+   int rc;
+   int i;
+
+   /* Make the cursor scrollable */
+   rc = SQLSetStmtAttr(hstmt, SQL_CURSOR_TYPE,
+                       (SQLPOINTER) SQL_CURSOR_STATIC, SQL_IS_UINTEGER);
+   CHECK_STMT_RESULT(rc, "SQLSetStmtAttr failed", hstmt);
+
+   /*
+    * Fetch a large result set without cursor (in Declare/fetch mode, it will
+    * be fetched in chunks)
+    */
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT 'foo' || g FROM generate_series(1, 3210) g", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+
+   /* Fetch the first 10 rows */
+   for (i = 0; i < 10; i++)
+   {
+       rc = SQLFetch(hstmt);
+       printFetchResult(hstmt, rc);
+   }
+
+   /* Test all the SQL_FETCH_* modes with SQLFetchScroll */
+   printf("Testing SQL_FETCH_NEXT...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
+   printFetchResult(hstmt, rc);
+
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_PRIOR...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_PRIOR, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_ABSOLUTE (5)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 5);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_RELATIVE (+2)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 2);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_RELATIVE (-2)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, -2);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_RELATIVE (+1)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 1);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_RELATIVE (0, no movement)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_FIRST...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_FIRST, 0);
+   printFetchResult(hstmt, rc);
+
+   /*** Ok, now test the behavior at "before first row" ***/
+   printf("Testing SQL_FETCH_PRIOR before first row...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_PRIOR, 0);
+   printFetchResult(hstmt, rc);
+
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_PRIOR, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_NEXT...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
+   printFetchResult(hstmt, rc);
+
+   /*** Test behavior at the end ***/
+
+   printf("Testing SQL_FETCH_LAST...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_LAST, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_LAST...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_LAST, 0);
+   printFetchResult(hstmt, rc);
+
+
+   printf("Testing SQL_FETCH_NEXT at the end of result set\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_NEXT at the end of result set\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("And SQL_FETCH_PRIOR...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_PRIOR, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing SQL_FETCH_RELATIVE (+10)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 10);
+   printFetchResult(hstmt, rc);
+
+   printf("And SQL_FETCH_PRIOR...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_PRIOR, 0);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing negative SQL_FETCH_ABSOLUTE (-5)...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, -5);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing negative SQL_FETCH_ABSOLUTE, before start...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, -10000);
+   printFetchResult(hstmt, rc);
+
+   printf("Testing  SQL_FETCH_ABSOLUTE, beoynd end...\n");
+   rc = SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 10000);
+   printFetchResult(hstmt, rc);
+
+   rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+   CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+}
+
+static const char *
+sql_commit_behavior_str(SQLUINTEGER info)
+{
+   static char buf[50];
+
+   switch(info)
+   {
+       case SQL_CB_DELETE:
+           return "SQL_CB_DELETE";
+
+       case SQL_CB_CLOSE:
+           return "SQL_CB_CLOSE";
+
+       case SQL_CB_PRESERVE:
+           return "SQL_CB_PRESERVE";
+
+       default:
+           sprintf(buf, "unknown (%u)", (unsigned int) info);
+           return buf;
+   }
+}
+
+int main(int argc, char **argv)
+{
+   int rc;
+   HSTMT hstmt = SQL_NULL_HSTMT;
+   SQLUSMALLINT info;
+
+   test_connect();
+
+   rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
+   if (!SQL_SUCCEEDED(rc))
+   {
+       print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
+       exit(1);
+   }
+
+   /*
+    * Print out the current SQL_CURSOR_COMMIT_BEHAVIOR and
+    * SQL_CURSOR_ROLLBACK settings. The result of this test case depends on
+    * those.
+    */
+   rc = SQLGetInfo(conn, SQL_CURSOR_COMMIT_BEHAVIOR, &info, sizeof(info), NULL);
+   CHECK_STMT_RESULT(rc, "SQLGetInfo failed", hstmt);
+   printf("SQL_CURSOR_COMMIT_BEHAVIOR: %s\n", sql_commit_behavior_str(info));
+
+   rc = SQLGetInfo(conn, SQL_CURSOR_ROLLBACK_BEHAVIOR, &info, sizeof(info), NULL);
+   CHECK_STMT_RESULT(rc, "SQLGetInfo failed", hstmt);
+   printf("SQL_CURSOR_ROLLBACK_BEHAVIOR: %s\n\n", sql_commit_behavior_str(info));
+
+   /* Run the test */
+   testLargeResult(hstmt);
+
+   /* Clean up */
+   test_disconnect();
+
+   return 0;
+}
index 6b185a7967d19bc98e9e136b08e6eec4fa8bdab4..e4070184fd40e316bc80b1dffe1a6a2e3e6910e1 100644 (file)
@@ -4,7 +4,8 @@
 
 #include "common.h"
 
-void testLargeResult(HSTMT hstmt, int betweenstmts)
+static void
+testLargeResult(HSTMT hstmt, int betweenstmts)
 {
    int rc;
    int i;
diff --git a/test/src/update-test.c b/test/src/update-test.c
new file mode 100644 (file)
index 0000000..2ddde39
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Test DML (INSERT, UPDATE, DELETE) commands
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+int main(int argc, char **argv)
+{
+   SQLRETURN rc;
+   HSTMT hstmt = SQL_NULL_HSTMT;
+   char param1[100];
+   SQLLEN cbParam1;
+   SQLCHAR *sql;
+   int i;
+   SQLLEN rowcount;
+
+   test_connect();
+
+   rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
+   if (!SQL_SUCCEEDED(rc))
+   {
+       print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
+       exit(1);
+   }
+
+   /* Prepare a test table */
+   sql = "CREATE TEMPORARY TABLE tmptable (i int4, t text)";
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed while creating temp table", hstmt);
+
+   /* Insert some rows, using a prepared statement */
+   rc = SQLPrepare(hstmt, (SQLCHAR *) "INSERT INTO tmptable VALUES (?, 'foobar')", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt);
+   for (i = 1; i <= 5; i++)
+   {
+       /* bind params  */
+       snprintf(param1, sizeof(param1), "%d", i);
+       cbParam1 = SQL_NTS;
+       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 failed", hstmt);
+
+       /* Execute */
+       rc = SQLExecute(hstmt);
+       CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt);
+
+       /* Test SQLRowCount() */
+       rc = SQLRowCount(hstmt, &rowcount);
+       CHECK_STMT_RESULT(rc, "SQLRowCount failed", hstmt);
+
+       printf("# of rows inserted: %d\n", (int) rowcount);
+
+       rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+       CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+   }
+
+   /* Update some rows */
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "UPDATE tmptable SET t = 'updated ' || i WHERE i <= 3" , SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+
+   rc = SQLRowCount(hstmt, &rowcount);
+   CHECK_STMT_RESULT(rc, "SQLRowCount failed", hstmt);
+   printf("# of rows updated: %d\n", (int) rowcount);
+
+   rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+   CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+   /* and delete some rows */
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "DELETE FROM tmptable WHERE i = 4 OR i = 2" , SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+
+   rc = SQLRowCount(hstmt, &rowcount);
+   CHECK_STMT_RESULT(rc, "SQLRowCount failed", hstmt);
+   printf("# of rows deleted: %d\n", (int) rowcount);
+
+   rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+   CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+   /* Print the contents of the table after all the updates to verify */
+
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT * FROM tmptable", SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+   print_result(hstmt);
+
+   /* Clean up */
+   test_disconnect();
+
+   return 0;
+}
index b4058979887f8d518ad0f7bc6b436d69d84fa506..bf1a2c1c27c89ad3e6d5a685b4fe717497c1aee1 100644 (file)
@@ -10,6 +10,7 @@
 TESTBINS = src/connect-test \
    src/stmthandles-test \
    src/select-test \
+   src/update-test \
    src/commands-test \
    src/multistmt-test \
    src/getresult-test \
@@ -25,7 +26,9 @@ TESTBINS = src/connect-test \
    src/alter-test \
    src/quotes-test \
    src/cursors-test \
+   src/cursor-movement-test \
    src/cursor-commit-test \
+   src/bookmark-test \
    src/declare-fetch-commit-test \
    src/positioned-update-test \
    src/catalogfunctions-test \