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