Line data Source code
1 : /* try all types from server */
2 :
3 : #undef NDEBUG
4 : #include <config.h>
5 :
6 : #include <stdio.h>
7 : #include <ctpublic.h>
8 : #include "common.h"
9 : #include <ctlib.h>
10 : #include <assert.h>
11 : #define TDS_DONT_DEFINE_DEFAULT_FUNCTIONS
12 : #include "../../tds/unittests/common.h"
13 : #include <freetds/tds.h>
14 :
15 : static CS_CONTEXT *ctx = NULL;
16 :
17 968 : static void test_type(TDSSOCKET *tds, TDSCOLUMN *col)
18 : {
19 : TDSRESULTINFO *resinfo, *bindinfo;
20 : TDSCOLUMN *oldcol, *bindcol;
21 : char out_buf[256];
22 : CS_INT len;
23 :
24 : /* we should be able to support a type coming from server */
25 968 : if (_ct_get_client_type(col, false) == CS_ILLEGAL_TYPE) {
26 0 : fprintf(stderr, "not supported\n");
27 0 : assert(0);
28 : }
29 :
30 : /* try to convert anyway, this should succeed */
31 968 : resinfo = tds_alloc_results(1);
32 968 : assert(resinfo);
33 968 : bindinfo = tds_alloc_results(1);
34 968 : assert(bindinfo);
35 :
36 : /* hack to pass our column to _ct_bind_data */
37 968 : oldcol = resinfo->columns[0];
38 968 : resinfo->columns[0] = col;
39 :
40 968 : memset(out_buf, '-', sizeof(out_buf));
41 968 : bindcol = bindinfo->columns[0];
42 968 : bindcol->column_varaddr = out_buf;
43 968 : bindcol->column_bindlen = sizeof(out_buf);
44 968 : bindcol->column_bindtype = CS_CHAR_TYPE;
45 968 : bindcol->column_bindfmt = CS_FMT_NULLTERM;
46 968 : len = -1;
47 968 : bindcol->column_lenbind = &len;
48 :
49 : /* every column should be at least be convertible to something */
50 968 : if (_ct_bind_data(ctx, resinfo, bindinfo, 0)) {
51 0 : fprintf(stderr, "conversion failed\n");
52 0 : assert(0);
53 : }
54 :
55 : /* just safety, we use small data for now */
56 968 : assert(len < sizeof(out_buf));
57 :
58 : /* we said terminated, check for terminator */
59 968 : assert(len >= 1 && len < sizeof(out_buf));
60 968 : assert(out_buf[len - 1] == 0);
61 968 : printf("output (%d): %s\n", len, out_buf);
62 :
63 968 : resinfo->columns[0] = oldcol;
64 968 : tds_free_results(resinfo);
65 968 : tds_free_results(bindinfo);
66 968 : }
67 :
68 : int
69 8 : main(int argc, char **argv)
70 : {
71 : TDSCONTEXT *tds_ctx;
72 : TDSSOCKET *tds;
73 : CS_RETCODE ret;
74 :
75 8 : tdsdump_open(getenv("TDSDUMP"));
76 :
77 8 : ret = cs_ctx_alloc(CS_VERSION_100, &ctx);
78 8 : assert(ret == CS_SUCCEED);
79 :
80 8 : tds_ctx = tds_alloc_context(NULL);
81 8 : assert(tds_ctx);
82 8 : tds = tds_alloc_socket(tds_ctx, 512);
83 8 : assert(tds);
84 8 : tds->conn->use_iconv = 0;
85 8 : if (TDS_FAILED(tds_iconv_open(tds->conn, "UTF-8", 1))) {
86 0 : fprintf(stderr, "Failed to initialize iconv\n");
87 0 : return 1;
88 : }
89 :
90 8 : tds_all_types(tds, test_type);
91 :
92 8 : tds_free_socket(tds);
93 8 : tds_free_context(tds_ctx);
94 :
95 8 : cs_ctx_drop(ctx);
96 :
97 8 : return 0;
98 : }
|