Line data Source code
1 : #include "common.h"
2 :
3 : #ifdef HAVE_UNISTD_H
4 : #include <unistd.h>
5 : #endif
6 :
7 : #include <assert.h>
8 :
9 : #include <freetds/utils.h>
10 : #include <freetds/replacements.h>
11 :
12 : /*
13 : * Test timeout on prepare
14 : * It execute a query wait for timeout and then try to issue a new prepare/execute
15 : * This test a BUG where second prepare timeouts
16 : *
17 : * Test from Ou Liu, cf "Query Time Out", 2006-08-08
18 : */
19 :
20 10 : TEST_MAIN()
21 : {
22 : int i;
23 :
24 10 : odbc_connect();
25 :
26 10 : odbc_command("create table #timeout(i int)");
27 10 : odbc_command("insert into #timeout values(1)");
28 :
29 30 : for (i = 0; i < 2; ++i) {
30 :
31 20 : printf("Loop %d\n", i);
32 :
33 20 : CHKSetStmtAttr(SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 10, SQL_IS_UINTEGER, "S");
34 :
35 20 : CHKPrepare(T("select * from #timeout"), SQL_NTS, "S");
36 20 : CHKExecute("S");
37 :
38 : do {
39 40 : while (CHKFetch("SNo") == SQL_SUCCESS)
40 : ;
41 20 : } while (CHKMoreResults("SNo") == SQL_SUCCESS);
42 :
43 20 : if (i == 0) {
44 10 : printf("Sleep 15 seconds to test if timeout occurs\n");
45 10 : tds_sleep_s(15);
46 : }
47 :
48 20 : SQLFreeStmt(odbc_stmt, SQL_CLOSE);
49 20 : SQLFreeStmt(odbc_stmt, SQL_UNBIND);
50 20 : SQLFreeStmt(odbc_stmt, SQL_RESET_PARAMS);
51 20 : SQLCloseCursor(odbc_stmt);
52 : }
53 :
54 10 : odbc_disconnect();
55 :
56 10 : ODBC_FREE();
57 10 : return 0;
58 : }
|