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

Generated by: LCOV version 1.13