1 #include "common.h"
2
3 #include <common/test_assert.h>
4
5 /* Test timeout of query */
6
7 static char software_version[] = "$Id: timeout.c 554130 2017-12-28 17:20:38Z ucko $";
8 static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
9
10 static void
AutoCommit(int onoff)11 AutoCommit(int onoff)
12 {
13 CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, int2ptr(onoff), 0, "S");
14 }
15
16 static void
EndTransaction(SQLSMALLINT type)17 EndTransaction(SQLSMALLINT type)
18 {
19 CHKEndTran(SQL_HANDLE_DBC, odbc_conn, type, "S");
20 }
21
22 int
main(int argc,char * argv[])23 main(int argc, char *argv[])
24 {
25 HENV env;
26 HDBC dbc;
27 HSTMT stmt;
28 SQLINTEGER i;
29
30 odbc_connect();
31
32 /* here we can't use temporary table cause we use two connection */
33 odbc_command_with_result(odbc_stmt, "drop table test_timeout");
34 odbc_command("create table test_timeout(n numeric(18,0) primary key, t varchar(30))");
35 AutoCommit(SQL_AUTOCOMMIT_OFF);
36
37 odbc_command("insert into test_timeout(n, t) values(1, 'initial')");
38 EndTransaction(SQL_COMMIT);
39
40 odbc_command("update test_timeout set t = 'second' where n = 1");
41
42 /* save this connection and do another */
43 env = odbc_env;
44 dbc = odbc_conn;
45 stmt = odbc_stmt;
46 odbc_env = SQL_NULL_HENV;
47 odbc_conn = SQL_NULL_HDBC;
48 odbc_stmt = SQL_NULL_HSTMT;
49
50 odbc_connect();
51
52 AutoCommit(SQL_AUTOCOMMIT_OFF);
53 CHKSetStmtAttr(SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 2, 0, "S");
54
55 i = 1;
56 CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &i, 0, NULL, "S");
57
58 CHKPrepare(T("update test_timeout set t = 'bad' where n = ?"), SQL_NTS, "S");
59 CHKExecute("E");
60 EndTransaction(SQL_ROLLBACK);
61
62 /* TODO should return error S1T00 Timeout expired, test error message */
63 odbc_command2("update test_timeout set t = 'bad' where n = 1", "E");
64
65 EndTransaction(SQL_ROLLBACK);
66
67 odbc_disconnect();
68
69 odbc_env = env;
70 odbc_conn = dbc;
71 odbc_stmt = stmt;
72
73 EndTransaction(SQL_COMMIT);
74
75 /* Sybase do not accept DROP TABLE during a transaction */
76 AutoCommit(SQL_AUTOCOMMIT_ON);
77 odbc_command("drop table test_timeout");
78
79 odbc_disconnect();
80
81 return 0;
82 }
83