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: 2026-07-19 14:02:14 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13