LCOV - code coverage report
Current view: top level - src/odbc/unittests - timeout.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 38 38 100.0 %
Date: 2025-01-18 12:13:41 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.13