LCOV - code coverage report
Current view: top level - src/odbc/unittests - t0002.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 22 22 100.0 %
Date: 2024-03-23 09:12:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : #define SWAP_STMT() do { SQLHSTMT xyz = odbc_stmt; \
       4             :         odbc_stmt = old_odbc_stmt; old_odbc_stmt = xyz; } while(0)
       5             : 
       6             : int
       7           8 : main(int argc, char *argv[])
       8             : {
       9           8 :         HSTMT old_odbc_stmt = SQL_NULL_HSTMT;
      10             : 
      11           8 :         odbc_connect();
      12             : 
      13           8 :         odbc_command("if object_id('tempdb..#odbctestdata') is not null drop table #odbctestdata");
      14             : 
      15           8 :         odbc_command("create table #odbctestdata (i int)");
      16           8 :         odbc_command("insert #odbctestdata values (123)");
      17             : 
      18             :         /*
      19             :          * now we allocate another statement, select, get all results
      20             :          * then make another query with first select and drop this statement
      21             :          * result should not disappear (required for DBD::ODBC)
      22             :          */
      23           8 :         SWAP_STMT();
      24           8 :         CHKAllocStmt(&odbc_stmt, "S");
      25             : 
      26           8 :         odbc_command("select * from #odbctestdata where 0=1");
      27             : 
      28           8 :         CHKFetch("No");
      29             : 
      30           8 :         CHKCloseCursor("SI");
      31             : 
      32           8 :         SWAP_STMT();
      33           8 :         odbc_command("select * from #odbctestdata");
      34           8 :         SWAP_STMT();
      35             : 
      36             :         /* drop first statement .. data should not disappear */
      37           8 :         CHKFreeStmt(SQL_DROP, "S");
      38             :         odbc_stmt = SQL_NULL_HSTMT;
      39           8 :         SWAP_STMT();
      40             : 
      41           8 :         CHKFetch("SI");
      42             : 
      43           8 :         CHKFetch("No");
      44             : 
      45           8 :         CHKCloseCursor("SI");
      46             : 
      47           8 :         odbc_command("drop table #odbctestdata");
      48             : 
      49           8 :         odbc_disconnect();
      50             : 
      51           8 :         printf("Done.\n");
      52             :         return 0;
      53             : }

Generated by: LCOV version 1.13