Improve regression test for reading a bytea column to SQL_C_CHAR.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 7 Oct 2014 07:14:38 +0000 (10:14 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 7 Oct 2014 07:17:22 +0000 (10:17 +0300)
When converting a bytea to SQL_C_CHAR, the driver uses upper-case letters in
the hex output, while the backend uses lower-case letters. That leads to
different output when using bytea_output=hex than with bytea_output=escape.
Set bytea_output explicitly in the regression test, so that it works
regardless of the current bytea_output setting. And test both settings - the
code path taken in the driver is quite different.

test/expected/result-conversions.out
test/src/result-conversions-test.c

index 851cd9fc496b0aa10029047a1cf13f1894c06a7a..73fbc23dee687f9d8d7f12427f9beeaa444b7100 100644 (file)
@@ -1,6 +1,7 @@
 \! "./src/result-conversions-test"
 connected
-Result set:
+Executed: SET intervalstyle=postgres
+Executed: SET bytea_output=escape
 'true' (boolean) as SQL_C_CHAR: 1
 'true' (boolean) as SQL_C_WCHAR: 1
 'true' (boolean) as SQL_C_SSHORT: 1
@@ -1345,6 +1346,9 @@ Result set:
 'foocur' (refcursor) as SQL_C_INTERVAL_HOUR_TO_MINUTE: interval sign: 0 unknown interval type: 0
 'foocur' (refcursor) as SQL_C_INTERVAL_HOUR_TO_SECOND: interval sign: 0 unknown interval type: 0
 'foocur' (refcursor) as SQL_C_INTERVAL_MINUTE_TO_SECOND: interval sign: 0 unknown interval type: 0
+Executed: SET bytea_output=hex
+'\x464F4F' (bytea) as SQL_C_CHAR: 464f4f
+'\x464F4F' (bytea) as SQL_C_WCHAR: 464f4f
 '543c5e21-435a-440b-943c-64af1ad571f1' (text) as SQL_C_GUID: d1: 543C5E21 d2: 435A d3: 440B d4: 943C64AF1AD571F1
 '2011-02-13' (date) as SQL_C_DATE: y: 2011 m: 2 d: 13
 '2011-02-13' (date) as SQL_C_TIMESTAMP: y: 2011 m: 2 d: 13 h: 0 m: 0 s: 0 f: 0
index 4864dd39a1c25626c60bba7f856704ce5d621480..98a55611666bd1da09898ec70a91dfe9dc9fc3cd 100644 (file)
@@ -462,6 +462,21 @@ test_conversion(const char *pgtype, const char *pgvalue, int sqltype, const char
    fflush(stdout);
 }
 
+/* A helper function to execute one command */
+void
+exec_cmd(char *sql)
+{
+   SQLRETURN   rc;
+
+   rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
+   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+
+   rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+   CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+   printf("Executed: %s\n", sql);
+}
+
 int main(int argc, char **argv)
 {
    SQLRETURN   rc;
@@ -482,12 +497,13 @@ int main(int argc, char **argv)
     * Someone should fix the driver to understand other formats,
     * postgres_verbose in particular...
     */
-   rc = SQLExecDirect(hstmt, (SQLCHAR *) "SET intervalstyle=postgres", SQL_NTS);
-   CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
-   print_result(hstmt);
+   exec_cmd("SET intervalstyle=postgres");
 
-   rc = SQLFreeStmt(hstmt, SQL_CLOSE);
-   CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+   /*
+    * Use octal escape bytea format in the tests. We will test the conversion
+    * from the hex format separately later.
+    */
+   exec_cmd("SET bytea_output=escape");
 
    /* Test all combinations of PostgreSQL data types and SQL datatypes */
    for (pgtype_i = 0; pgtypes[pgtype_i * 2] != NULL; pgtype_i++)
@@ -509,6 +525,16 @@ int main(int argc, char **argv)
     * above.
     */
 
+   /* Conversions from bytea, in the hex format */
+
+   /*
+    * Use octal escape bytea format in the tests. We will test the conversion
+    * from the hex format separately later.
+    */
+   exec_cmd("SET bytea_output=hex");
+   test_conversion("bytea", "\\x464F4F", SQL_C_CHAR, "SQL_C_CHAR", 100);
+   test_conversion("bytea", "\\x464F4F", SQL_C_WCHAR, "SQL_C_WCHAR", 100);
+
    /* Conversion to GUID throws error if the string is not of correct form */
    test_conversion("text", "543c5e21-435a-440b-943c-64af1ad571f1", SQL_C_GUID, "SQL_C_GUID", -1);