LCOV - code coverage report
Current view: top level - src/odbc/unittests - closestmt.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 24 24 100.0 %
Date: 2025-05-05 12:32:54 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_use_version3 = 1;
      17          10 :         odbc_connect();
      18             : 
      19             :         /* create a table with some rows */
      20          10 :         odbc_command("create table #tmp (i int, c varchar(100))");
      21          10 :         odbc_command("insert into #tmp values(1, 'some data')");
      22          90 :         for (i = 0; i < 8; ++i) {
      23          80 :                 sprintf(sql, "insert into #tmp select i+%d, c from #tmp where i <= %d", 1 << i, 1 << i);
      24          80 :                 odbc_command(sql);
      25             :         }
      26             : 
      27             :         /* execute a prepared query on the connection and get all rows */
      28          10 :         CHKPrepare(T("select i from #tmp where i < ?"), SQL_NTS, "S");
      29             : 
      30          10 :         num = 5;
      31          10 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 0, 0, &num, 0, NULL, "S");
      32             : 
      33          10 :         CHKExecute("S");
      34             : 
      35          50 :         for (i = 1; i < 5; ++i)
      36          40 :                 CHKFetch("S");
      37          10 :         CHKFetch("No");
      38          10 :         CHKMoreResults("No");
      39             : 
      40             :         /* start getting some data from another statement */
      41          10 :         CHKAllocStmt(&stmt, "S");
      42          10 :         SWAP_STMT(stmt);
      43             : 
      44          10 :         CHKExecDirect(T("select * from #tmp"), SQL_NTS, "S");
      45             : 
      46             :         /* close first statement with data pending on second */
      47          10 :         SWAP_STMT(stmt);
      48          10 :         CHKFreeStmt(SQL_DROP, "S");
      49             : 
      50          10 :         SWAP_STMT(stmt);
      51          10 :         odbc_disconnect();
      52          10 :         return 0;
      53             : }

Generated by: LCOV version 1.13