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