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