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,
28 : 0, &ind, "S");
29 48 : CHKExecute("S");
30 48 : ODBC_FREE();
31 48 : }
32 :
33 10 : TEST_MAIN()
34 : {
35 10 : odbc_use_version3 = 1;
36 10 : odbc_connect();
37 :
38 10 : odbc_command("create table #test_output (id int, msg text)");
39 :
40 10 : Test("?", SQL_INTEGER, "?", SQL_LONGVARCHAR);
41 10 : Test("123", SQL_INTEGER, "?", SQL_LONGVARCHAR);
42 10 : Test("?", SQL_INTEGER, "'foo'", SQL_LONGVARCHAR);
43 10 : Test("?", SQL_INTEGER, "?", SQL_VARCHAR);
44 :
45 : /*
46 : * Sybase cannot pass this test without complicated query parsing.
47 : * Query with blob columns cannot be prepared so prepared query must
48 : * be emulated loosing column information from server and Sybase do
49 : * not convert implicitly VARCHAR to INT
50 : */
51 10 : if (odbc_db_is_microsoft())
52 8 : Test("?", SQL_VARCHAR, "?", SQL_LONGVARCHAR);
53 : else
54 2 : ++test_num;
55 :
56 10 : odbc_disconnect();
57 :
58 10 : return 0;
59 : }
|