1 #include "common.h"
2
3 #include <common/test_assert.h>
4
5 /*
6 * This test attempt to test if closing a statement with prepared query
7 * success if there are a pending query on the same connection from
8 * another statement.
9 */
10
11 #define SWAP_STMT(b) do { SQLHSTMT xyz = odbc_stmt; odbc_stmt = b; b = xyz; } while(0)
12
13 int
main(int argc,char * argv[])14 main(int argc, char *argv[])
15 {
16 char sql[128];
17 int i;
18 SQLHSTMT stmt;
19 SQLINTEGER num;
20
21 odbc_use_version3 = 1;
22 odbc_connect();
23
24 /* create a table with some rows */
25 odbc_command("create table #tmp (i int, c varchar(100))");
26 odbc_command("insert into #tmp values(1, 'some data')");
27 for (i = 0; i < 8; ++i) {
28 sprintf(sql, "insert into #tmp select i+%d, c from #tmp where i <= %d", 1 << i, 1 << i);
29 odbc_command(sql);
30 }
31
32 /* execute a prepared query on the connection and get all rows */
33 CHKPrepare(T("select i from #tmp where i < ?"), SQL_NTS, "S");
34
35 num = 5;
36 CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &num, 0, NULL, "S");
37
38 CHKExecute("S");
39
40 for (i = 1; i < 5; ++i)
41 CHKFetch("S");
42 CHKFetch("No");
43 CHKMoreResults("No");
44
45 /* start getting some data from another statement */
46 CHKAllocStmt(&stmt, "S");
47 SWAP_STMT(stmt);
48
49 CHKExecDirect(T("select * from #tmp"), SQL_NTS, "S");
50
51 /* close first statement with data pending on second */
52 SWAP_STMT(stmt);
53 CHKFreeStmt(SQL_DROP, "S");
54
55 SWAP_STMT(stmt);
56 odbc_disconnect();
57 return 0;
58 }
59