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

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /*
       4             :  * This test attempt to test if closing a statement with prepared query
       5             :  * success if there are a pending query on the same connection from
       6             :  * another statement.
       7             :  */
       8             : 
       9             : #define SWAP_STMT(b) do { SQLHSTMT xyz = odbc_stmt; odbc_stmt = b; b = xyz; } while(0)
      10             : 
      11             : int
      12           8 : main(int argc, char *argv[])
      13             : {
      14             :         char sql[128];
      15             :         int i;
      16             :         SQLHSTMT stmt;
      17             :         SQLINTEGER num;
      18             : 
      19           8 :         odbc_use_version3 = 1;
      20           8 :         odbc_connect();
      21             : 
      22             :         /* create a table with some rows */
      23           8 :         odbc_command("create table #tmp (i int, c varchar(100))");
      24           8 :         odbc_command("insert into #tmp values(1, 'some data')");
      25          72 :         for (i = 0; i < 8; ++i) {
      26          64 :                 sprintf(sql, "insert into #tmp select i+%d, c from #tmp where i <= %d", 1 << i, 1 << i);
      27          64 :                 odbc_command(sql);
      28             :         }
      29             : 
      30             :         /* execute a prepared query on the connection and get all rows */
      31           8 :         CHKPrepare(T("select i from #tmp where i < ?"), SQL_NTS, "S");
      32             : 
      33           8 :         num = 5;
      34           8 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &num, 0, NULL, "S");
      35             : 
      36           8 :         CHKExecute("S");
      37             : 
      38          40 :         for (i = 1; i < 5; ++i)
      39          32 :                 CHKFetch("S");
      40           8 :         CHKFetch("No");
      41           8 :         CHKMoreResults("No");
      42             : 
      43             :         /* start getting some data from another statement */
      44           8 :         CHKAllocStmt(&stmt, "S");
      45           8 :         SWAP_STMT(stmt);
      46             : 
      47           8 :         CHKExecDirect(T("select * from #tmp"), SQL_NTS, "S");
      48             : 
      49             :         /* close first statement with data pending on second */
      50           8 :         SWAP_STMT(stmt);
      51           8 :         CHKFreeStmt(SQL_DROP, "S");
      52             : 
      53           8 :         SWAP_STMT(stmt);
      54           8 :         odbc_disconnect();
      55             :         return 0;
      56             : }

Generated by: LCOV version 1.13