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

Generated by: LCOV version 1.13