--- /dev/null
+/* Test parameter quoting, with standard_conforming_strings on/off */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "common.h"
+
+static void
+execWithParam(HSTMT hstmt, char *param)
+{
+ SQLLEN cbParam1;
+ int rc;
+
+ /* 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 */
+ param, /* param value ptr */
+ 0, /* buffer len */
+ &cbParam1 /* StrLen_or_IndPtr */);
+ CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt);
+
+ rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT 'foo' UNION ALL SELECT ?", SQL_NTS);
+ CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+ print_result(hstmt);
+
+ 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;
+ char sql[100000];
+ char *sqlend;
+ int i;
+ char *strings[] = {
+ "param'quote",
+ "param\\backslash",
+ "ends with backslash\\",
+ NULL };
+
+ test_connect();
+
+ rc = SQLAllocStmt(conn, &hstmt);
+ if (!SQL_SUCCEEDED(rc))
+ {
+ print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
+ exit(1);
+ }
+
+ rc = SQLExecDirect(hstmt, (SQLCHAR *) "SET standard_conforming_strings=on", SQL_NTS);
+ CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+ print_result(hstmt);
+ rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+ CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+ for (i = 0; strings[i] != NULL; i++)
+ execWithParam(hstmt, strings[i]);
+
+ rc = SQLExecDirect(hstmt, (SQLCHAR *) "SET standard_conforming_strings=off", SQL_NTS);
+ CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
+ print_result(hstmt);
+ rc = SQLFreeStmt(hstmt, SQL_CLOSE);
+ CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
+
+ for (i = 0; strings[i] != NULL; i++)
+ execWithParam(hstmt, strings[i]);
+
+ /* Clean up */
+ test_disconnect();
+}
+