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