Line data Source code
1 : #include "common.h"
2 :
3 : #include <stdarg.h>
4 :
5 : static CS_CONNECTION *conn = NULL;
6 :
7 : /* Testing: Retrieve CS_TEXT_TYPE using ct_bind() */
8 10 : TEST_MAIN()
9 : {
10 : CS_CONTEXT *ctx;
11 : CS_COMMAND *cmd;
12 10 : int i, verbose = 0;
13 :
14 : CS_RETCODE ret;
15 : CS_RETCODE ret2;
16 : CS_RETCODE results_ret;
17 : CS_INT result_type;
18 : CS_INT num_cols;
19 :
20 : CS_DATAFMT datafmt;
21 : CS_INT datalength;
22 : CS_SMALLINT ind;
23 10 : CS_INT count, row_count = 0;
24 :
25 : CS_INT id;
26 : CS_CHAR name[600];
27 : CS_CHAR *nameptr;
28 : CS_INT getlen;
29 :
30 : char large_sql[1024];
31 : char len600[601];
32 : char len800[801];
33 : char temp[11];
34 :
35 : char *textptr;
36 : CS_IODESC iodesc;
37 :
38 : int tds_version;
39 :
40 10 : len600[0] = 0;
41 10 : name[0] = 0;
42 610 : for (i = 0; i < 60; i++) {
43 600 : sprintf(temp, "_abcde_%03d", (i + 1) * 10);
44 600 : strcat(len600, temp);
45 : }
46 10 : len600[600] = '\0';
47 :
48 10 : len800[0] = 0;
49 810 : for (i = 0; i < 80; i++) {
50 800 : sprintf(temp, "_zzzzz_%03d", (i + 1) * 10);
51 800 : strcat(len800, temp);
52 : }
53 10 : len800[800] = '\0';
54 :
55 :
56 10 : printf("%s: Retrieve CS_TEXT_TYPE using ct_bind()\n", __FILE__);
57 : if (verbose) {
58 : printf("Trying login\n");
59 : }
60 10 : check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
61 :
62 10 : check_call(ct_con_props, (conn, CS_GET, CS_TDS_VERSION, &tds_version, CS_UNUSED, NULL));
63 : #ifdef CS_TDS_72
64 10 : if (tds_version >= CS_TDS_72) {
65 4 : printf("Protocol TDS7.2+ detected, test not supported\n");
66 4 : try_ctlogout(ctx, conn, cmd, verbose);
67 4 : return 0;
68 : }
69 : #endif
70 :
71 6 : check_call(run_command, (cmd, "CREATE TABLE #test_table (id int, name text)"));
72 :
73 6 : sprintf(large_sql, "INSERT #test_table (id, name) VALUES (2, '%s')", len600);
74 6 : check_call(run_command, (cmd, large_sql));
75 :
76 6 : check_call(ct_command, (cmd, CS_LANG_CMD, "SELECT id, name FROM #test_table", CS_NULLTERM, CS_UNUSED));
77 6 : check_call(ct_send, (cmd));
78 6 : while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
79 12 : switch ((int) result_type) {
80 : case CS_CMD_SUCCEED:
81 : break;
82 : case CS_CMD_DONE:
83 : break;
84 0 : case CS_CMD_FAIL:
85 0 : fprintf(stderr, "ct_results() result_type CS_CMD_FAIL.\n");
86 0 : return 1;
87 6 : case CS_ROW_RESULT:
88 6 : check_call(ct_res_info, (cmd, CS_NUMDATA, &num_cols, CS_UNUSED, NULL));
89 6 : if (num_cols != 2) {
90 0 : fprintf(stderr, "num_cols %d != 2", num_cols);
91 0 : return 1;
92 : }
93 :
94 6 : check_call(ct_describe, (cmd, 1, &datafmt));
95 6 : datafmt.format = CS_FMT_UNUSED;
96 6 : if (datafmt.maxlength > 1024) {
97 0 : datafmt.maxlength = 1024;
98 : }
99 6 : check_call(ct_bind, (cmd, 1, &datafmt, &id, &datalength, &ind));
100 :
101 6 : while (((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
102 6 : || (ret == CS_ROW_FAIL)) {
103 6 : row_count += count;
104 6 : if (ret == CS_ROW_FAIL) {
105 0 : fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
106 0 : return 1;
107 : } else { /* ret == CS_SUCCEED */
108 : if (verbose) {
109 : printf("id = '%d'\n", id);
110 : }
111 :
112 : nameptr = name;
113 18 : while ((ret2 = ct_get_data(cmd, 2 , nameptr, 200, &getlen )) == CS_SUCCEED) {
114 12 : nameptr += getlen;
115 : }
116 6 : if (ret2 != CS_END_DATA) {
117 0 : fprintf(stderr, "ct_get_data() failed\n");
118 0 : return 1;
119 : }
120 :
121 6 : if (memcmp(name, len600, 600)) {
122 0 : fprintf(stderr, "Bad return data\n");
123 0 : return 1;
124 : }
125 6 : printf("%s: Trying ct_data_info on text column\n", __FILE__);
126 :
127 6 : check_call(ct_data_info, (cmd, CS_GET, 2, &iodesc));
128 :
129 6 : printf("datatype = %d\n", iodesc.datatype);
130 6 : printf("usertype = %d\n", iodesc.usertype);
131 6 : printf("text len = %d\n", iodesc.total_txtlen);
132 6 : printf("name = %*.*s\n", iodesc.namelen, iodesc.namelen, iodesc.name);
133 6 : if (iodesc.datatype != CS_TEXT_TYPE) {
134 0 : fprintf(stderr, "Unexpected datatype %d\n", iodesc.datatype);
135 0 : return 1;
136 : }
137 : }
138 : }
139 6 : switch ((int) ret) {
140 : case CS_END_DATA:
141 : break;
142 0 : case CS_FAIL:
143 0 : fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
144 0 : return 1;
145 0 : default:
146 0 : fprintf(stderr, "ct_fetch() unexpected return.\n");
147 0 : return 1;
148 : }
149 : break;
150 0 : case CS_COMPUTE_RESULT:
151 0 : fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
152 0 : return 1;
153 0 : default:
154 0 : fprintf(stderr, "ct_results() unexpected result_type.\n");
155 0 : return 1;
156 : }
157 : }
158 6 : switch ((int) results_ret) {
159 : case CS_END_RESULTS:
160 : break;
161 0 : case CS_FAIL:
162 0 : fprintf(stderr, "ct_results() failed.\n");
163 0 : return 1;
164 : break;
165 0 : default:
166 0 : fprintf(stderr, "ct_results() unexpected return.\n");
167 0 : return 1;
168 : }
169 :
170 6 : check_call(ct_command, (cmd, CS_SEND_DATA_CMD, NULL, CS_UNUSED, CS_COLUMN_DATA));
171 :
172 6 : iodesc.total_txtlen = 800;
173 6 : iodesc.log_on_update = CS_TRUE;
174 :
175 6 : check_call(ct_data_info, (cmd, CS_SET, CS_UNUSED, &iodesc));
176 :
177 30 : for ( i = 0 ; i < 800 ; i += 200 ) {
178 24 : textptr = &len800[i];
179 :
180 24 : check_call(ct_send_data, (cmd, textptr, (CS_INT) 200));
181 : }
182 6 : check_call(ct_send, (cmd));
183 :
184 6 : while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
185 16 : switch ((int) result_type) {
186 : case CS_CMD_SUCCEED:
187 : break;
188 : case CS_CMD_DONE:
189 : break;
190 0 : case CS_CMD_FAIL:
191 0 : fprintf(stderr, "ct_results() result_type CS_CMD_FAIL.\n");
192 0 : return 1;
193 : case CS_ROW_RESULT:
194 : break;
195 : case CS_PARAM_RESULT:
196 : break;
197 0 : case CS_COMPUTE_RESULT:
198 0 : fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
199 0 : return 1;
200 0 : default:
201 0 : fprintf(stderr, "ct_results() unexpected result_type.\n");
202 0 : return 1;
203 : }
204 : }
205 6 : switch ((int) results_ret) {
206 : case CS_END_RESULTS:
207 : break;
208 0 : case CS_FAIL:
209 0 : fprintf(stderr, "ct_results() failed.\n");
210 0 : return 1;
211 : break;
212 0 : default:
213 0 : fprintf(stderr, "ct_results() unexpected return.\n");
214 0 : return 1;
215 : }
216 :
217 : if (verbose) {
218 : printf("Trying logout\n");
219 : }
220 6 : check_call(try_ctlogout, (ctx, conn, cmd, verbose));
221 :
222 6 : return 0;
223 : }
|