psqlodbc.git / summary / log / commit / refs
commit 3eef5ea2f973f9ce2ffd9da4ff92070db6537d63
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Mon Dec 22 18:19:45 2014 +0000
Add a test case for error handling.
The current behavior isn't actually quite correct with some configurations,
but seems better to add the regression test now anyway, even though the
errors_2.out basically memorizes the bogus behavior. It should be removed
when the bug is fixed.
Makefile.am | 4 ++
test/expected/errors.out | 12 ++++++
test/expected/errors_1.out | 12 ++++++
test/expected/errors_2.out | 12 ++++++
test/src/errors-test.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++
test/tests | 1 +
6 files changed, 135 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 1bacce8a..ed24e0d0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -108,6 +108,9 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
test/expected/declare-fetch-commit-test.out \
test/expected/deprecated.out \
test/expected/diagnostic.out \
+ test/expected/errors.out \
+ test/expected/errors_1.out \
+ test/expected/errors_2.out \
test/expected/error-rollback.out \
test/expected/getresult.out \
test/expected/insertreturning.out \
@@ -154,6 +157,7 @@ EXTRA_DIST = license.txt readme.txt readme_winbuild.txt \
test/src/declare-fetch-commit-test.c \
test/src/deprecated-test.c \
test/src/diagnostic-test.c \
+ test/src/errors-test.c \
test/src/error-rollback-test.c \
test/src/getresult-test.c \
test/src/insertreturning-test.c \
diff --git a/test/expected/errors.out b/test/expected/errors.out
new file mode 100644
index 00000000..965f4fc3
--- /dev/null
+++ b/test/expected/errors.out
@@ -0,0 +1,12 @@
+\! "./src/errors-test"
+connected
+
+42703=ERROR: column "doesnotexist" does not exist;
+Error while executing the query
+
+42703=ERROR: column "doesnotexist2" does not exist;
+Error while executing the query
+
+42703=ERROR: column "doesnotexist3" does not exist;
+Error while preparing parameters
+disconnecting
diff --git a/test/expected/errors_1.out b/test/expected/errors_1.out
new file mode 100644
index 00000000..49d169d0
--- /dev/null
+++ b/test/expected/errors_1.out
@@ -0,0 +1,12 @@
+\! "./src/errors-test"
+connected
+
+42703=ERROR: column "doesnotexist" does not exist;
+Error while executing the query
+
+42703=ERROR: column "doesnotexist2" does not exist;
+Error while executing the query
+
+42703=ERROR: column "doesnotexist3" does not exist;
+Error while executing the query
+disconnecting
diff --git a/test/expected/errors_2.out b/test/expected/errors_2.out
new file mode 100644
index 00000000..3a37f897
--- /dev/null
+++ b/test/expected/errors_2.out
@@ -0,0 +1,12 @@
+\! "./src/errors-test"
+connected
+
+42703=ERROR: column "doesnotexist" does not exist;
+Error while executing the query
+
+25P02=ERROR: current transaction is aborted, commands ignored until end of transaction block;
+Error while executing the query
+
+25P02=ERROR: current transaction is aborted, commands ignored until end of transaction block;
+Error while executing the query
+disconnecting
diff --git a/test/src/errors-test.c b/test/src/errors-test.c
new file mode 100644
index 00000000..311d17cd
--- /dev/null
+++ b/test/src/errors-test.c
@@ -0,0 +1,94 @@
+/*
+ * Test behavior when errors happen. Should get a proper error message, and
+ * the connection should stay in a sane state.
+ *
+ * FIXME: With some combinations of settings, an error can leave a
+ * transaction open, but in aborted state. That's a bug in the driver, but
+ * because I'm not planning to fix it right now, there is an expected output
+ * file (errors_2.out) for that. The bug should be fixed, and the expected
+ * output removed.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+int
+main(int argc, char **argv)
+{
+ SQLRETURN rc;
+ HSTMT hstmt = SQL_NULL_HSTMT;
+ char param1[20] = "foo";
+ SQLLEN cbParam1;
+
+ 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);
+ }
+
+ /* Test a simple parse-time error */
+ rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT doesnotexist", SQL_NTS);
+ /* Print error, it is expected */
+ if (!SQL_SUCCEEDED(rc))
+ print_diag("", SQL_HANDLE_STMT, hstmt);
+
+ rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+ CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+ /* The same, but with a bind parameter */
+
+ /* bind param */
+ 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);
+
+ /* Test a simple parse-time error */
+ rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT doesnotexist2 WHERE bogus = ?", SQL_NTS);
+ /* Print error, it is expected */
+ if (!SQL_SUCCEEDED(rc))
+ print_diag("", SQL_HANDLE_STMT, hstmt);
+
+ rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+ CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+ /*** Test syntax error with SQLPrepare ***/
+
+ /* Test a simple parse-time error */
+ rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT doesnotexist3 WHERE bogus = ?", SQL_NTS);
+
+ /* bind param */
+ 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);
+
+ /* Test a simple parse-time error */
+ rc = SQLExecute(hstmt);
+ /* Print error, it is expected */
+ if (!SQL_SUCCEEDED(rc))
+ print_diag("", SQL_HANDLE_STMT, hstmt);
+
+
+ test_disconnect();
+
+ return 0;
+}
diff --git a/test/tests b/test/tests
index d5f8b6c1..5d359b74 100644
--- a/test/tests
+++ b/test/tests
@@ -39,6 +39,7 @@ TESTBINS = src/connect-test \
src/lfconversion-test \
src/cte-test \
src/deprecated-test \
+ src/errors-test \
src/error-rollback-test \
src/diagnostic-test \
src/numeric-test \
[parent: 1c5340610463]