LCOV - code coverage report
Current view: top level - src/tds/unittests - t0004.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 33 42 78.6 %
Date: 2024-04-18 20:40:06 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 *
      23             : varchar_as_string(TDSSOCKET * tds, int col_idx)
      24             : {
      25             :         static char result[256];
      26             :         const void *value = tds->res_info->columns[col_idx]->column_data;
      27             : 
      28             :         strlcpy(result, (const char *) value, sizeof(result));
      29             :         return result;
      30             : }
      31             : 
      32             : 
      33             : int
      34           8 : main(void)
      35             : {
      36             :         TDSLOGIN *login;
      37             :         TDSSOCKET *tds;
      38           8 :         int verbose = 0;
      39             :         int rc, i;
      40             : 
      41             :         int result_type;
      42           8 :         int rows_returned = 0;
      43             : 
      44           8 :         const char *len200 =
      45             :                 "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
      46           8 :         char *long_query = (char*) malloc(5000);
      47             : 
      48           8 :         strcpy(long_query, "SELECT name FROM #longquerytest WHERE (");
      49         168 :         for (i = 0; i < 20; ++i)
      50         160 :                 sprintf(strchr(long_query, 0), "name = '%c%s' OR ", 'A'+i, len200);
      51           8 :         strcat(long_query, "name = 'correct')");
      52             : 
      53           8 :         printf("%s: Test large (>4096 bytes) queries\n", __FILE__);
      54           8 :         rc = try_tds_login(&login, &tds, __FILE__, verbose);
      55           8 :         if (rc != TDS_SUCCESS) {
      56           0 :                 fprintf(stderr, "try_tds_login() failed\n");
      57           0 :                 return 1;
      58             :         }
      59             : 
      60             :         /* do not check error here, if TABLE is not create this give error */
      61           8 :         rc = run_query(tds, "DROP TABLE #longquerytest");
      62           8 :         rc = run_query(tds, "CREATE TABLE #longquerytest (name varchar(255))");
      63           8 :         if (rc != TDS_SUCCESS) {
      64             :                 return 1;
      65             :         }
      66           8 :         rc = run_query(tds, "INSERT #longquerytest (name) VALUES ('incorrect')");
      67           8 :         if (rc != TDS_SUCCESS) {
      68             :                 return 1;
      69             :         }
      70           8 :         rc = run_query(tds, "INSERT #longquerytest (name) VALUES ('correct')");
      71           8 :         if (rc != TDS_SUCCESS) {
      72             :                 return 1;
      73             :         }
      74             : 
      75             :         /*
      76             :          * The heart of the test
      77             :          */
      78             :         if (verbose) {
      79             :                 printf("block size %d\n", tds->conn->env.block_size);
      80             :         }
      81           8 :         rc = tds_submit_query(tds, long_query);
      82          32 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROWFMT|TDS_RETURN_ROW)) == TDS_SUCCESS) {
      83          16 :                 switch (result_type) {
      84           8 :                 case TDS_ROWFMT_RESULT:
      85           8 :                         if (tds->res_info->columns[0]->column_type != SYBVARCHAR) {
      86           0 :                                 fprintf(stderr, "Wrong column_type in %s\n", __FILE__);
      87           0 :                                 return 1;
      88             :                         }
      89             :                         break;
      90           8 :                 case TDS_ROW_RESULT:
      91           8 :                         ++rows_returned;
      92             :                         if (verbose) {
      93             :                                 printf("col 0 is %s\n", varchar_as_string(tds, 0));
      94             :                         }
      95             :                         break;
      96             :                 default:
      97             :                         break;
      98             :                 }
      99             :         }
     100           8 :         if (rc == TDS_FAIL) {
     101           0 :                 fprintf(stderr, "tds_process_tokens() returned TDS_FAIL for long query\n");
     102           0 :                 return 1;
     103           8 :         } else if (rc != TDS_NO_MORE_RESULTS) {
     104           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
     105             :         }
     106             : 
     107           8 :         if (rows_returned != 1) {
     108           0 :                 fprintf(stderr, "%d rows returned, 1 expected\n", rows_returned);
     109           0 :                 return 1;
     110             :         }
     111             : 
     112             :         /* do not check error here, if TABLE is not create this give error */
     113           8 :         rc = run_query(tds, "DROP TABLE #longquerytest");
     114             : 
     115           8 :         try_tds_logout(login, tds, verbose);
     116           8 :         free(long_query);
     117           8 :         return 0;
     118             : }

Generated by: LCOV version 1.13