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

Generated by: LCOV version 1.13