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

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /* Test for SQLMoreResults and SQLRowCount on batch */
       4             : 
       5             : static char software_version[] = "$Id: moreandcount.c,v 1.20 2011-07-12 10:16:59 freddy77 Exp $";
       6             : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
       7             : 
       8             : static void
       9          16 : DoTest(int prepare)
      10             : {
      11          16 :         int n = 0;
      12             :         static const char query[] =
      13             :                 /* on prepared this recordset should be skipped */
      14             :                 "DECLARE @b INT SELECT @b = 25 "
      15             :                 "SELECT * FROM #tmp1 WHERE i <= 3 "
      16             :                 /* on prepare we cannot distinguish these recordset */
      17             :                 "INSERT INTO #tmp2 SELECT * FROM #tmp1 WHERE i = 1 "
      18             :                 "INSERT INTO #tmp2 SELECT * FROM #tmp1 WHERE i <= 3 "
      19             :                 "SELECT * FROM #tmp1 WHERE i = 1 "
      20             :                 /* but FreeTDS can detect last recordset */
      21             :                 "UPDATE #tmp1 SET i=i+1 WHERE i >= 2";
      22             : 
      23          16 :         if (prepare) {
      24           8 :                 CHKPrepare(T(query), SQL_NTS, "S");
      25           8 :                 CHKExecute("S");
      26             :         } else {
      27             : 
      28             :                 /* execute a batch command select insert insert select and check rows */
      29           8 :                 CHKExecDirect(T(query), SQL_NTS, "S");
      30             :         }
      31          16 :         if (!prepare) {
      32           8 :                 printf("Result %d\n", ++n);
      33           8 :                 ODBC_CHECK_COLS(0);
      34           8 :                 ODBC_CHECK_ROWS(1);
      35           8 :                 CHKMoreResults("S");
      36             :         }
      37          16 :         printf("Result %d\n", ++n);
      38          16 :         ODBC_CHECK_COLS(1);
      39          16 :         ODBC_CHECK_ROWS(-1);
      40          16 :         CHKFetch("S");
      41          16 :         CHKFetch("S");
      42          16 :         ODBC_CHECK_COLS(1);
      43          16 :         ODBC_CHECK_ROWS(-1);
      44          16 :         CHKFetch("No");
      45          16 :         ODBC_CHECK_COLS(1);
      46          16 :         ODBC_CHECK_ROWS(2);
      47          16 :         CHKMoreResults("S");
      48          16 :         if (!prepare) {
      49           8 :                 printf("Result %d\n", ++n);
      50           8 :                 ODBC_CHECK_COLS(0);
      51           8 :                 ODBC_CHECK_ROWS(1);
      52           8 :                 CHKMoreResults("S");
      53           8 :                 printf("Result %d\n", ++n);
      54           8 :                 ODBC_CHECK_COLS(0);
      55           8 :                 ODBC_CHECK_ROWS(2);
      56           8 :                 CHKMoreResults("S");
      57             :         }
      58          16 :         printf("Result %d\n", ++n);
      59          16 :         ODBC_CHECK_COLS(1);
      60          16 :         ODBC_CHECK_ROWS(-1);
      61          16 :         CHKFetch("S");
      62          16 :         ODBC_CHECK_COLS(1);
      63          16 :         ODBC_CHECK_ROWS(-1);
      64          16 :         CHKFetch("No");
      65          16 :         ODBC_CHECK_COLS(1);
      66          16 :         if (prepare) {
      67             :                 /* collapse 2 recordset... after a lot of testing this is the behavior! */
      68           8 :                 if (odbc_driver_is_freetds())
      69           8 :                         ODBC_CHECK_ROWS(2);
      70             :         } else {
      71           8 :                 ODBC_CHECK_ROWS(1);
      72           8 :                 CHKMoreResults("S");
      73           8 :                 ODBC_CHECK_COLS(0);
      74           8 :                 ODBC_CHECK_ROWS(2);
      75             :         }
      76             : 
      77          16 :         CHKMoreResults("No");
      78             : #ifndef TDS_NO_DM
      79             :         if (!prepare)
      80             :                 ODBC_CHECK_COLS(-1);
      81             :         ODBC_CHECK_ROWS(-2);
      82             : #endif
      83          16 :         ODBC_FREE();
      84          16 : }
      85             : 
      86             : int
      87           8 : main(int argc, char *argv[])
      88             : {
      89           8 :         odbc_connect();
      90             : 
      91           8 :         odbc_command("create table #tmp1 (i int)");
      92           8 :         odbc_command("create table #tmp2 (i int)");
      93           8 :         odbc_command("insert into #tmp1 values(1)");
      94           8 :         odbc_command("insert into #tmp1 values(2)");
      95           8 :         odbc_command("insert into #tmp1 values(5)");
      96             : 
      97           8 :         printf("Use direct statement\n");
      98           8 :         DoTest(0);
      99             : 
     100           8 :         printf("Use prepared statement\n");
     101           8 :         DoTest(1);
     102             : 
     103           8 :         odbc_disconnect();
     104             : 
     105           8 :         printf("Done.\n");
     106             :         return 0;
     107             : }

Generated by: LCOV version 1.13