LCOV - code coverage report
Current view: top level - src/odbc/unittests - print.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 47 51 92.2 %
Date: 2024-03-23 08:24:27 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : static SQLCHAR output[256];
       4             : 
       5             : #ifdef TDS_NO_DM
       6             : static const int tds_no_dm = 1;
       7             : #else
       8             : static const int tds_no_dm = 0;
       9             : #endif
      10             : 
      11             : static int
      12          16 : test(int odbc3)
      13             : {
      14             :         SQLLEN cnamesize;
      15             :         const char *query;
      16             : 
      17          16 :         odbc_use_version3 = odbc3;
      18             : 
      19          16 :         odbc_connect();
      20             : 
      21             :         /* issue print statement and test message returned */
      22          16 :         output[0] = 0;
      23          16 :         query = "print 'START' select count(*) from sysobjects where name='sysobjects' print 'END'";
      24          16 :         odbc_command2(query, "I");
      25          16 :         odbc_read_error();
      26          16 :         if (!strstr(odbc_err, "START")) {
      27           0 :                 printf("Message invalid\n");
      28           0 :                 return 1;
      29             :         }
      30          16 :         odbc_err[0] = 0;
      31             : 
      32          16 :         if (odbc3) {
      33           8 :                 ODBC_CHECK_COLS(0);
      34           8 :                 ODBC_CHECK_ROWS(-1);
      35           8 :                 CHKFetch("E");
      36           8 :                 CHKMoreResults("S");
      37             :         }
      38             :     
      39          16 :         ODBC_CHECK_COLS(1);
      40          16 :         ODBC_CHECK_ROWS(-1);
      41             : 
      42          16 :         CHKFetch("S");
      43          16 :         ODBC_CHECK_COLS(1);
      44          16 :         ODBC_CHECK_ROWS(-1);
      45             :         /* check no data */
      46          16 :         CHKFetch("No");
      47          16 :         ODBC_CHECK_COLS(1);
      48          16 :         ODBC_CHECK_ROWS(1);
      49             : 
      50             :         /* SQLMoreResults return NO DATA or SUCCESS WITH INFO ... */
      51          16 :         if (tds_no_dm && !odbc3)
      52           8 :                 CHKMoreResults("No");
      53             :         else if (odbc3)
      54           8 :                 CHKMoreResults("I");
      55             :         else
      56             :                 CHKMoreResults("INo");
      57             : 
      58             :         /*
      59             :          * ... but read error
      60             :          * (unixODBC till 2.2.11 do not read errors on NO DATA, skip test)
      61             :          */
      62             :         if (tds_no_dm || odbc3) {
      63          16 :                 odbc_read_error();
      64          16 :                 if (!strstr(odbc_err, "END")) {
      65           0 :                         printf("Message invalid\n");
      66           0 :                         return 1;
      67             :                 }
      68          16 :                 odbc_err[0] = 0;
      69             :         }
      70             : 
      71          16 :         if (odbc3) {
      72           8 :                 ODBC_CHECK_COLS(0);
      73           8 :                 ODBC_CHECK_ROWS(-1);
      74             : 
      75           8 :                 CHKMoreResults("No");
      76             :         }
      77             : 
      78             :         /* issue invalid command and test error */
      79          16 :         odbc_command2("SELECT donotexistsfield FROM donotexiststable", "E");
      80          16 :         odbc_read_error();
      81             : 
      82             :         /* test no data returned */
      83          16 :         CHKFetch("E");
      84          16 :         odbc_read_error();
      85             : 
      86          16 :         CHKGetData(1, SQL_C_CHAR, output, sizeof(output), &cnamesize, "E");
      87          16 :         odbc_read_error();
      88             : 
      89          16 :         odbc_disconnect();
      90             : 
      91          16 :         return 0;
      92             : }
      93             : 
      94             : int
      95           8 : main(void)
      96             : {
      97             :         int ret;
      98             : 
      99             :         /* ODBC 2 */
     100           8 :         ret = test(0);
     101           8 :         if (ret != 0)
     102             :                 return ret;
     103             : 
     104             :         /* ODBC 3 */
     105           8 :         ret = test(1);
     106           8 :         if (ret != 0)
     107             :                 return ret;
     108             : 
     109           8 :         printf("Done.\n");
     110           8 :         return 0;
     111             : }
     112             : 

Generated by: LCOV version 1.13