LCOV - code coverage report
Current view: top level - src/tds/unittests - t0005.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 26 34 76.5 %
Date: 2025-04-26 20:22:58 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 1998-1999  Brian Bruns
       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             : #include <freetds/replacements.h>
      21             : 
      22             : static char *value_as_string(TDSSOCKET * tds, int col_idx);
      23             : 
      24          10 : TEST_MAIN()
      25             : {
      26             :         TDSLOGIN *login;
      27             :         TDSSOCKET *tds;
      28          10 :         int verbose = 0;
      29             :         int rc;
      30             :         int i;
      31             : 
      32             :         int result_type;
      33             : 
      34          10 :         const char *len200 =
      35             :                 "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
      36             :         char large_sql[1000];
      37             : 
      38          10 :         printf("%s: Test large (>512 bytes) replies\n", __FILE__);
      39          10 :         rc = try_tds_login(&login, &tds, __FILE__, verbose);
      40          10 :         if (rc != TDS_SUCCESS) {
      41           0 :                 fprintf(stderr, "try_tds_login() failed\n");
      42           0 :                 return 1;
      43             :         }
      44             : 
      45             :         /* do not test error, remove always table */
      46          10 :         rc = run_query(tds, "DROP TABLE #test_table");
      47          10 :         rc = run_query(tds, "CREATE TABLE #test_table (id int, name varchar(255))");
      48          10 :         if (rc != TDS_SUCCESS) {
      49             :                 return 1;
      50             :         }
      51             : 
      52          10 :         sprintf(large_sql, "INSERT #test_table (id, name) VALUES (0, 'A%s')", len200);
      53          10 :         rc = run_query(tds, large_sql);
      54          10 :         if (rc != TDS_SUCCESS) {
      55             :                 return 1;
      56             :         }
      57          10 :         sprintf(large_sql, "INSERT #test_table (id, name) VALUES (1, 'B%s')", len200);
      58          10 :         rc = run_query(tds, large_sql);
      59          10 :         if (rc != TDS_SUCCESS) {
      60             :                 return 1;
      61             :         }
      62          10 :         sprintf(large_sql, "INSERT #test_table (id, name) VALUES (2, 'C%s')", len200);
      63          10 :         rc = run_query(tds, large_sql);
      64          10 :         if (rc != TDS_SUCCESS) {
      65             :                 return 1;
      66             :         }
      67             : 
      68             :         /*
      69             :          * The heart of the test
      70             :          */
      71          10 :         rc = tds_submit_query(tds, "SELECT * FROM #test_table");
      72          50 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROW)) == TDS_SUCCESS) {
      73          30 :                 switch (result_type) {
      74             :                 case TDS_ROW_RESULT:
      75             :                         for (i = 0; i < tds->res_info->num_cols; i++) {
      76             :                                 if (verbose) {
      77             :                                         printf("col %i is %s\n", i, value_as_string(tds, i));
      78             :                                 }
      79             :                         }
      80             :                         break;
      81           0 :                 default:
      82           0 :                         fprintf(stderr, "tds_process_tokens() returned unexpected result\n");
      83           0 :                         break;
      84             :                 }
      85             :         }
      86          10 :         if (rc == TDS_FAIL) {
      87           0 :                 fprintf(stderr, "tds_process_tokens() returned TDS_FAIL for SELECT\n");
      88           0 :                 return 1;
      89          10 :         } else if (rc != TDS_NO_MORE_RESULTS) {
      90           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
      91             :         }
      92             : 
      93             :         /* do not test error, remove always table */
      94          10 :         rc = run_query(tds, "DROP TABLE #test_table");
      95             : 
      96          10 :         try_tds_logout(login, tds, verbose);
      97          10 :         return 0;
      98             : }
      99             : 
     100             : static char *
     101             : value_as_string(TDSSOCKET * tds, int col_idx)
     102             : {
     103             :         static char result[256];
     104             :         const int type = tds->res_info->columns[col_idx]->column_type;
     105             :         const void *value = tds->res_info->columns[col_idx]->column_data;
     106             : 
     107             :         switch (type) {
     108             :         case SYBVARCHAR:
     109             :                 strlcpy(result, (const char *) value, sizeof(result));
     110             :                 break;
     111             :         case SYBINT4:
     112             :                 sprintf(result, "%d", *(const int *) value);
     113             :                 break;
     114             :         default:
     115             :                 sprintf(result, "Unexpected column_type %d", type);
     116             :                 break;
     117             :         }
     118             :         return result;
     119             : }

Generated by: LCOV version 1.13