Line data Source code
1 : #include "common.h"
2 :
3 : /* Testing: Retrieve CS_TEXT_TYPE using ct_bind() */
4 10 : TEST_MAIN()
5 : {
6 : CS_CONTEXT *ctx;
7 : CS_CONNECTION *conn;
8 : CS_COMMAND *cmd;
9 10 : int i, verbose = 0;
10 :
11 : CS_RETCODE ret;
12 : CS_RETCODE results_ret;
13 : CS_INT result_type;
14 : CS_INT num_cols;
15 :
16 : CS_DATAFMT datafmt;
17 : CS_INT datalength;
18 : CS_SMALLINT ind;
19 10 : CS_INT count, row_count = 0;
20 :
21 : CS_CHAR name[1024];
22 : char large_sql[1024];
23 : char len600[601];
24 : char temp[11];
25 :
26 10 : len600[0] = 0;
27 10 : name[0] = 0;
28 610 : for (i = 0; i < 60; i++) {
29 600 : sprintf(temp, "_abcde_%03d", (i + 1) * 10);
30 600 : strcat(len600, temp);
31 : }
32 10 : len600[600] = '\0';
33 :
34 10 : printf("%s: Retrieve CS_TEXT_TYPE using ct_bind()\n", __FILE__);
35 : if (verbose) {
36 : printf("Trying login\n");
37 : }
38 10 : check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
39 :
40 10 : check_call(run_command, (cmd, "CREATE TABLE #test_table (id int, name text)"));
41 : /*
42 : check_call(run_command, (cmd, "INSERT #test_table (id, name) VALUES (1, 'name1')"));
43 : */
44 10 : sprintf(large_sql, "INSERT #test_table (id, name) VALUES (2, '%s')", len600);
45 10 : check_call(run_command, (cmd, large_sql));
46 :
47 10 : check_call(ct_command, (cmd, CS_LANG_CMD, "SELECT name FROM #test_table", CS_NULLTERM, CS_UNUSED));
48 10 : check_call(ct_send, (cmd));
49 10 : while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
50 20 : switch ((int) result_type) {
51 : case CS_CMD_SUCCEED:
52 : break;
53 : case CS_CMD_DONE:
54 : break;
55 0 : case CS_CMD_FAIL:
56 0 : fprintf(stderr, "ct_results() result_type CS_CMD_FAIL.\n");
57 0 : return 1;
58 10 : case CS_ROW_RESULT:
59 10 : check_call(ct_res_info, (cmd, CS_NUMDATA, &num_cols, CS_UNUSED, NULL));
60 10 : if (num_cols != 1) {
61 0 : fprintf(stderr, "num_cols %d != 1", num_cols);
62 0 : return 1;
63 : }
64 10 : check_call(ct_describe, (cmd, 1, &datafmt));
65 10 : datafmt.format = CS_FMT_NULLTERM;
66 10 : if (datafmt.maxlength > 1024) {
67 10 : datafmt.maxlength = 1024;
68 : }
69 10 : check_call(ct_bind, (cmd, 1, &datafmt, name, &datalength, &ind));
70 :
71 10 : while (((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
72 10 : || (ret == CS_ROW_FAIL)) {
73 10 : row_count += count;
74 10 : if (ret == CS_ROW_FAIL) {
75 0 : fprintf(stderr, "ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
76 0 : return 1;
77 : } else { /* ret == CS_SUCCEED */
78 : if (verbose) {
79 : printf("name = '%s'\n", name);
80 : }
81 10 : if (strcmp(name, len600)) {
82 0 : fprintf(stderr, "Bad return:\n'%s'\n! =\n'%s'\n", name, len600);
83 0 : return 1;
84 : }
85 10 : if (datalength != strlen(name) + 1) {
86 0 : fprintf(stderr, "Bad count:\n'%ld'\n! =\n'%d'\n", (long) strlen(name) + 1, count);
87 0 : return 1;
88 : }
89 : }
90 : }
91 10 : switch ((int) ret) {
92 : case CS_END_DATA:
93 : break;
94 0 : case CS_FAIL:
95 0 : fprintf(stderr, "ct_fetch() returned CS_FAIL.\n");
96 0 : return 1;
97 0 : default:
98 0 : fprintf(stderr, "ct_fetch() unexpected return.\n");
99 0 : return 1;
100 : }
101 : break;
102 0 : case CS_COMPUTE_RESULT:
103 0 : fprintf(stderr, "ct_results() unexpected CS_COMPUTE_RESULT.\n");
104 0 : return 1;
105 0 : default:
106 0 : fprintf(stderr, "ct_results() unexpected result_type.\n");
107 0 : return 1;
108 : }
109 : }
110 10 : switch ((int) results_ret) {
111 : case CS_END_RESULTS:
112 : break;
113 0 : case CS_FAIL:
114 0 : fprintf(stderr, "ct_results() failed.\n");
115 0 : return 1;
116 : break;
117 0 : default:
118 0 : fprintf(stderr, "ct_results() unexpected return.\n");
119 0 : return 1;
120 : }
121 :
122 : if (verbose) {
123 : printf("Trying logout\n");
124 : }
125 10 : check_call(try_ctlogout, (ctx, conn, cmd, verbose));
126 :
127 10 : return 0;
128 : }
|