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