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

Generated by: LCOV version 1.13