Line data Source code
1 : /*
2 : * test SQLBindParameter with text and Sybase
3 : * test from Keith Woodard (bug #885122)
4 : */
5 : #include "common.h"
6 :
7 : static int test_num = 0;
8 :
9 : static void
10 48 : Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2)
11 : {
12 : char sql[512];
13 48 : char *val = "test";
14 48 : SQLLEN ind = 4;
15 48 : int id = 1;
16 48 : ODBC_BUF *odbc_buf = NULL;
17 :
18 48 : SQLFreeStmt(odbc_stmt, SQL_RESET_PARAMS);
19 :
20 48 : ++test_num;
21 48 : sprintf(sql, "insert into #test_output values (%s, %s)", bind1, bind2);
22 :
23 48 : CHKPrepare(T(sql), (SQLINTEGER) strlen(sql), "S");
24 48 : if (bind1[0] == '?')
25 38 : CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_LONG, type1, 3, 0, &test_num, 0, &ind, "S");
26 48 : if (bind2[0] == '?')
27 38 : CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_CHAR, type2, strlen(val) + 1, 0, (SQLCHAR *) val, 0, &ind, "S");
28 48 : CHKExecute("S");
29 48 : ODBC_FREE();
30 48 : }
31 :
32 10 : TEST_MAIN()
33 : {
34 10 : odbc_connect();
35 :
36 10 : odbc_command("create table #test_output (id int, msg text)");
37 :
38 10 : Test("?", SQL_INTEGER, "?", SQL_LONGVARCHAR);
39 10 : Test("123", SQL_INTEGER, "?", SQL_LONGVARCHAR);
40 10 : Test("?", SQL_INTEGER, "'foo'", SQL_LONGVARCHAR);
41 10 : Test("?", SQL_INTEGER, "?", SQL_VARCHAR);
42 :
43 : /*
44 : * Sybase cannot pass this test without complicated query parsing.
45 : * Query with blob columns cannot be prepared so prepared query must
46 : * be emulated loosing column information from server and Sybase do
47 : * not convert implicitly VARCHAR to INT
48 : */
49 10 : if (odbc_db_is_microsoft())
50 8 : Test("?", SQL_VARCHAR, "?", SQL_LONGVARCHAR);
51 : else
52 2 : ++test_num;
53 :
54 10 : odbc_disconnect();
55 :
56 10 : return 0;
57 : }
|