Line data Source code
1 : #include "common.h"
2 : #include <ctype.h>
3 :
4 : /*
5 : * SQLDescribeCol test
6 : */
7 : static int g_result = 0;
8 :
9 : static void
10 : do_check(int c, const char *test, int line)
11 : {
12 24 : if (c)
13 : return;
14 :
15 0 : fprintf(stderr, "Failed check %s at line %d\n", test, line);
16 0 : g_result = 1;
17 : }
18 :
19 : #define check(s) do_check(s, #s, __LINE__)
20 :
21 : int
22 8 : main(void)
23 : {
24 : SQLSMALLINT len, type;
25 : SQLTCHAR name[128];
26 :
27 8 : odbc_connect();
28 8 : odbc_command("create table #dc (col_name int, name2 varchar(100))");
29 :
30 8 : odbc_command("select * from #dc");
31 :
32 8 : len = 0x1234;
33 8 : CHKDescribeCol(1, NULL, 0, &len, &type, NULL, NULL, NULL, "S");
34 16 : check(len == 8);
35 :
36 8 : len = 0x1234;
37 8 : CHKDescribeCol(2, name, 0, &len, &type, NULL, NULL, NULL, "I");
38 16 : check(len == 5);
39 :
40 8 : len = 0x1234;
41 8 : CHKDescribeCol(1, NULL, 2, &len, &type, NULL, NULL, NULL, "S");
42 16 : check(len == 8);
43 :
44 8 : len = 0x1234;
45 8 : strcpy((char *) name, "xxx");
46 8 : CHKDescribeCol(2, name, 3, &len, &type, NULL, NULL, NULL, "I");
47 16 : check(len == 5 && strcmp(C(name), "na") == 0);
48 :
49 8 : len = 0x1234;
50 8 : strcpy((char *) name, "xxx");
51 8 : CHKDescribeCol(1, name, 1, &len, &type, NULL, NULL, NULL, "I");
52 16 : check(len == 8 && strcmp(C(name), "") == 0);
53 :
54 8 : len = 0x1234;
55 8 : strcpy((char *) name, "xxx");
56 8 : CHKDescribeCol(2, name, 6, &len, &type, NULL, NULL, NULL, "S");
57 16 : check(len == 5 && strcmp(C(name), "name2") == 0);
58 :
59 8 : odbc_disconnect();
60 :
61 8 : if (g_result == 0)
62 8 : printf("Done.\n");
63 8 : return g_result;
64 : }
|