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