\! "./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
'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
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;
* 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++)
* 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);