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: 2024-04-18 21:21:48 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             : int
      22           8 : main(int argc, char **argv)
      23             : {
      24             :         TDSLOGIN *login;
      25             :         TDSSOCKET *tds;
      26           8 :         int verbose = 1;
      27             :         int rc;
      28             :         int i;
      29             : 
      30             :         TDSCOLUMN *curcol;
      31             :         TDSRESULTINFO *resinfo;
      32             : 
      33             :         int result_type;
      34             : 
      35           8 :         printf("%s: Test null values\n", __FILE__);
      36           8 :         rc = try_tds_login(&login, &tds, __FILE__, verbose);
      37           8 :         if (rc != TDS_SUCCESS) {
      38           0 :                 fprintf(stderr, "try_tds_login() failed\n");
      39           0 :                 return 1;
      40             :         }
      41             : 
      42           8 :         rc = tds_submit_query(tds, "SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL");
      43             : 
      44          24 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROW|TDS_RETURN_COMPUTE)) == TDS_SUCCESS) {
      45           8 :                 switch (result_type) {
      46           8 :                 case TDS_ROW_RESULT:
      47           8 :                         resinfo = tds->res_info;
      48         120 :                         for (i = 0; i < 14; i++) {
      49         112 :                                 curcol = resinfo->columns[i];
      50         112 :                                 if (curcol->column_cur_size != -1) {
      51           0 :                                         fprintf(stderr, "NULL value expected\n");
      52           0 :                                         return 1;
      53             :                                 }
      54             :                         }
      55             :                 case TDS_COMPUTE_RESULT:
      56             :                         break;
      57           0 :                 default:
      58           0 :                         fprintf(stderr, "tds_process_tokens() unexpected result\n");
      59           0 :                         break;
      60             :                 }
      61             :         }
      62           8 :         if (rc == TDS_FAIL) {
      63           0 :                 fprintf(stderr, "query failed\n");
      64           0 :                 return 1;
      65             :         }
      66           8 :         if (rc != TDS_NO_MORE_RESULTS) {
      67           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
      68             :         }
      69             : 
      70           8 :         rc = tds_submit_query(tds, "SELECT 12, 'abc', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL");
      71          24 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROW|TDS_RETURN_COMPUTE)) == TDS_SUCCESS) {
      72           8 :                 switch (result_type) {
      73           8 :                 case TDS_ROW_RESULT:
      74           8 :                         resinfo = tds->res_info;
      75             : 
      76           8 :                         curcol = resinfo->columns[0];
      77           8 :                         if (curcol->column_type != SYBINT4) {
      78           0 :                                 fprintf(stderr, "SYBINT value expected\n");
      79           0 :                                 return 1;
      80             :                         }
      81           8 :                         if (*(TDS_INT*)curcol->column_data != 12) {
      82           0 :                                 fprintf(stderr, "invalid integer returned\n");
      83           0 :                                 return 1;
      84             :                         }
      85             : 
      86           8 :                         curcol = resinfo->columns[1];
      87           8 :                         if (curcol->column_type != SYBVARCHAR) {
      88           0 :                                 fprintf(stderr, "SYBVARCHAR value expected\n");
      89           0 :                                 return 1;
      90             :                         }
      91           8 :                         if (strcmp((char *) curcol->column_data, "abc") != 0) {
      92           0 :                                 fprintf(stderr, "invalid string returned\n");
      93           0 :                                 return 1;
      94             :                         }
      95             : 
      96          96 :                         for (i = 2; i < 14; i++) {
      97          96 :                                 curcol = resinfo->columns[i];
      98          96 :                                 if (curcol->column_cur_size != -1) {
      99           0 :                                         fprintf(stderr, "NULL value expected\n");
     100           0 :                                         return 1;
     101             :                                 }
     102             :                         }
     103             :                 case TDS_COMPUTE_RESULT:
     104             :                         break;
     105           0 :                 default:
     106           0 :                         fprintf(stderr, "tds_process_tokens() unexpected result\n");
     107           0 :                         break;
     108             :                 }
     109             :         }
     110           8 :         if (rc == TDS_FAIL) {
     111           0 :                 fprintf(stderr, "query failed\n");
     112           0 :                 return 1;
     113             :         }
     114           8 :         if (rc != TDS_NO_MORE_RESULTS) {
     115           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
     116             :         }
     117             : 
     118           8 :         try_tds_logout(login, tds, verbose);
     119           8 :         return 0;
     120             : }

Generated by: LCOV version 1.13