From 901551035c8583b3eb42238f5188b4754bd2c58b Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 7 Oct 2014 10:14:38 +0300 Subject: [PATCH] Improve regression test for reading a bytea column to SQL_C_CHAR. 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 | 6 ++++- test/src/result-conversions-test.c | 36 ++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/test/expected/result-conversions.out b/test/expected/result-conversions.out index 851cd9f..73fbc23 100644 --- a/test/expected/result-conversions.out +++ b/test/expected/result-conversions.out @@ -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 diff --git a/test/src/result-conversions-test.c b/test/src/result-conversions-test.c index 4864dd3..98a5561 100644 --- a/test/src/result-conversions-test.c +++ b/test/src/result-conversions-test.c @@ -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); -- 2.39.5