Line data Source code
1 : /* Test some data from server. Currently tests MS XML type */
2 : #include "common.h"
3 :
4 10 : TEST_MAIN()
5 : {
6 : CS_CONTEXT *ctx;
7 : CS_CONNECTION *conn;
8 : CS_COMMAND *cmd;
9 10 : bool verbose = false;
10 :
11 : CS_RETCODE ret;
12 : CS_INT result_type;
13 : CS_INT num_cols;
14 :
15 : CS_DATAFMT datafmt;
16 10 : CS_INT copied = 0;
17 10 : CS_SMALLINT ind = 0;
18 : CS_INT count;
19 :
20 : const char *select;
21 :
22 : char buffer[128];
23 :
24 : int tds_version;
25 :
26 10 : printf("%s: test data from server\n", __FILE__);
27 : if (verbose) {
28 : printf("Trying login\n");
29 : }
30 10 : check_call(try_ctlogin_with_options, (argc, argv, &ctx, &conn, &cmd, verbose));
31 10 : if (common_pwd.fverbose)
32 0 : verbose = true;
33 :
34 10 : ret = ct_con_props(conn, CS_GET, CS_TDS_VERSION, &tds_version, CS_UNUSED, NULL);
35 10 : if (ret == CS_SUCCEED) {
36 : #ifdef CS_TDS_71
37 10 : switch (tds_version) {
38 4 : case CS_TDS_70:
39 : case CS_TDS_71:
40 4 : fprintf(stderr, "This TDS version does not support XML.\n");
41 4 : try_ctlogout(ctx, conn, cmd, verbose);
42 4 : return 0;
43 : }
44 : #endif
45 : }
46 :
47 6 : select = "select cast('<a b=\"aaa\"><b>ciao</b>hi</a>' as xml) as name";
48 6 : printf("%s\n", select);
49 :
50 6 : check_call(ct_command, (cmd, CS_LANG_CMD, (CS_CHAR *) select, CS_NULLTERM, CS_UNUSED));
51 :
52 6 : check_call(ct_send, (cmd));
53 :
54 6 : check_call(ct_results, (cmd, &result_type));
55 :
56 6 : switch (result_type) {
57 2 : case CS_CMD_FAIL:
58 2 : fprintf(stderr, "ct_results() result_type CS_CMD_FAIL, probably not MSSQL.\n");
59 2 : try_ctlogout(ctx, conn, cmd, verbose);
60 2 : return 0;
61 : case CS_ROW_RESULT:
62 : break;
63 0 : default:
64 0 : fprintf(stderr, "ct_results() unexpected return %d.\n", result_type);
65 : goto Cleanup;
66 : }
67 :
68 4 : check_call(ct_res_info, (cmd, CS_NUMDATA, &num_cols, CS_UNUSED, NULL));
69 4 : assert(num_cols == 1);
70 :
71 4 : check_call(ct_describe, (cmd, 1, &datafmt));
72 :
73 4 : assert(strcmp(datafmt.name, "name") == 0);
74 4 : assert(datafmt.datatype == CS_LONGCHAR_TYPE);
75 4 : assert(datafmt.maxlength == 0x7fffffff);
76 4 : assert(datafmt.scale == 0);
77 4 : assert(datafmt.precision == 0);
78 :
79 4 : datafmt.format = CS_FMT_NULLTERM;
80 4 : datafmt.maxlength = 100;
81 :
82 4 : printf("binding column 1\n");
83 4 : check_call(ct_bind, (cmd, 1, &datafmt, buffer, &copied, &ind));
84 :
85 4 : printf("fetching rows.\n");
86 12 : while ((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED) {
87 4 : fprintf(stderr, "ct_fetch() returned %d.\n", (int) ret);
88 4 : buffer[copied] = '\0';
89 4 : fprintf(stderr, "copied %d bytes: [%s]\n", copied, buffer);
90 : }
91 4 : assert(ret == CS_END_DATA);
92 :
93 : do {
94 8 : ret = ct_results(cmd, &result_type);
95 8 : } while (ret == CS_SUCCEED);
96 :
97 4 : assert(ret == CS_END_RESULTS);
98 :
99 4 : if (verbose) {
100 0 : printf("Trying logout\n");
101 : }
102 4 : check_call(try_ctlogout, (ctx, conn, cmd, verbose));
103 :
104 4 : return 0;
105 :
106 0 : Cleanup:
107 0 : try_ctlogout(ctx, conn, cmd, verbose);
108 0 : return 1;
109 : }
|