LCOV - code coverage report
Current view: top level - src/tds/unittests - nulls.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 33 59 55.9 %
Date: 2025-04-25 08:22:23 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 2014 Mikhail Denisenko
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Library General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2 of the License, or (at your option) any later version.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Library General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Library General Public
      15             :  * License along with this library; if not, write to the
      16             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17             :  * Boston, MA 02111-1307, USA.
      18             :  */
      19             : #include "common.h"
      20             : 
      21          10 : TEST_MAIN()
      22             : {
      23             :         TDSLOGIN *login;
      24             :         TDSSOCKET *tds;
      25          10 :         int verbose = 1;
      26             :         int rc;
      27             :         int i;
      28             : 
      29             :         TDSCOLUMN *curcol;
      30             :         TDSRESULTINFO *resinfo;
      31             : 
      32             :         int result_type;
      33             : 
      34          10 :         printf("%s: Test null values\n", __FILE__);
      35          10 :         rc = try_tds_login(&login, &tds, __FILE__, verbose);
      36          10 :         if (rc != TDS_SUCCESS) {
      37           0 :                 fprintf(stderr, "try_tds_login() failed\n");
      38           0 :                 return 1;
      39             :         }
      40             : 
      41          10 :         rc = tds_submit_query(tds, "SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL");
      42             : 
      43          30 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROW|TDS_RETURN_COMPUTE)) == TDS_SUCCESS) {
      44          10 :                 switch (result_type) {
      45          10 :                 case TDS_ROW_RESULT:
      46          10 :                         resinfo = tds->res_info;
      47         150 :                         for (i = 0; i < 14; i++) {
      48         140 :                                 curcol = resinfo->columns[i];
      49         140 :                                 if (curcol->column_cur_size != -1) {
      50           0 :                                         fprintf(stderr, "NULL value expected\n");
      51           0 :                                         return 1;
      52             :                                 }
      53             :                         }
      54             :                 case TDS_COMPUTE_RESULT:
      55             :                         break;
      56           0 :                 default:
      57           0 :                         fprintf(stderr, "tds_process_tokens() unexpected result\n");
      58           0 :                         break;
      59             :                 }
      60             :         }
      61          10 :         if (rc == TDS_FAIL) {
      62           0 :                 fprintf(stderr, "query failed\n");
      63           0 :                 return 1;
      64             :         }
      65          10 :         if (rc != TDS_NO_MORE_RESULTS) {
      66           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
      67             :         }
      68             : 
      69          10 :         rc = tds_submit_query(tds, "SELECT 12, 'abc', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL");
      70          30 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROW|TDS_RETURN_COMPUTE)) == TDS_SUCCESS) {
      71          10 :                 switch (result_type) {
      72          10 :                 case TDS_ROW_RESULT:
      73          10 :                         resinfo = tds->res_info;
      74             : 
      75          10 :                         curcol = resinfo->columns[0];
      76          10 :                         if (curcol->column_type != SYBINT4) {
      77           0 :                                 fprintf(stderr, "SYBINT value expected\n");
      78           0 :                                 return 1;
      79             :                         }
      80          10 :                         if (*(TDS_INT*)curcol->column_data != 12) {
      81           0 :                                 fprintf(stderr, "invalid integer returned\n");
      82           0 :                                 return 1;
      83             :                         }
      84             : 
      85          10 :                         curcol = resinfo->columns[1];
      86          10 :                         if (curcol->column_type != SYBVARCHAR) {
      87           0 :                                 fprintf(stderr, "SYBVARCHAR value expected\n");
      88           0 :                                 return 1;
      89             :                         }
      90          10 :                         if (strcmp((char *) curcol->column_data, "abc") != 0) {
      91           0 :                                 fprintf(stderr, "invalid string returned\n");
      92           0 :                                 return 1;
      93             :                         }
      94             : 
      95         120 :                         for (i = 2; i < 14; i++) {
      96         120 :                                 curcol = resinfo->columns[i];
      97         120 :                                 if (curcol->column_cur_size != -1) {
      98           0 :                                         fprintf(stderr, "NULL value expected\n");
      99           0 :                                         return 1;
     100             :                                 }
     101             :                         }
     102             :                 case TDS_COMPUTE_RESULT:
     103             :                         break;
     104           0 :                 default:
     105           0 :                         fprintf(stderr, "tds_process_tokens() unexpected result\n");
     106           0 :                         break;
     107             :                 }
     108             :         }
     109          10 :         if (rc == TDS_FAIL) {
     110           0 :                 fprintf(stderr, "query failed\n");
     111           0 :                 return 1;
     112             :         }
     113          10 :         if (rc != TDS_NO_MORE_RESULTS) {
     114           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
     115             :         }
     116             : 
     117          10 :         try_tds_logout(login, tds, verbose);
     118          10 :         return 0;
     119             : }

Generated by: LCOV version 1.13