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