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: 2025-10-24 03:11:41 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.13