LCOV - code coverage report
Current view: top level - src/odbc/unittests - timeout2.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 20 20 100.0 %
Date: 2024-04-18 20:40:06 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : #ifdef HAVE_UNISTD_H
       4             : #include <unistd.h>
       5             : #endif
       6             : 
       7             : #include <assert.h>
       8             : 
       9             : #include <freetds/utils.h>
      10             : #include <freetds/replacements.h>
      11             : 
      12             : /*
      13             :  * Test timeout on prepare
      14             :  * It execute a query wait for timeout and then try to issue a new prepare/execute
      15             :  * This test a BUG where second prepare timeouts
      16             :  *
      17             :  * Test from Ou Liu, cf "Query Time Out", 2006-08-08
      18             :  */
      19             : 
      20             : int
      21           8 : main(void)
      22             : {
      23             :         int i;
      24             : 
      25           8 :         odbc_connect();
      26             : 
      27           8 :         odbc_command("create table #timeout(i int)");
      28           8 :         odbc_command("insert into #timeout values(1)");
      29             : 
      30          24 :         for (i = 0; i < 2; ++i) {
      31             : 
      32          16 :                 printf("Loop %d\n", i);
      33             : 
      34          16 :                 CHKSetStmtAttr(SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 10, SQL_IS_UINTEGER, "S");
      35             : 
      36          16 :                 CHKPrepare(T("select * from #timeout"), SQL_NTS, "S");
      37          16 :                 CHKExecute("S");
      38             : 
      39             :                 do {
      40          32 :                         while (CHKFetch("SNo") == SQL_SUCCESS)
      41             :                                 ;
      42          16 :                 } while (CHKMoreResults("SNo") == SQL_SUCCESS);
      43             : 
      44          16 :                 if (i == 0) {
      45           8 :                         printf("Sleep 15 seconds to test if timeout occurs\n");
      46           8 :                         tds_sleep_s(15);
      47             :                 }
      48             : 
      49          16 :                 SQLFreeStmt(odbc_stmt, SQL_CLOSE);
      50          16 :                 SQLFreeStmt(odbc_stmt, SQL_UNBIND);
      51          16 :                 SQLFreeStmt(odbc_stmt, SQL_RESET_PARAMS);
      52          16 :                 SQLCloseCursor(odbc_stmt);
      53             :         }
      54             : 
      55           8 :         odbc_disconnect();
      56             : 
      57           8 :         ODBC_FREE();
      58             :         return 0;
      59             : }

Generated by: LCOV version 1.13