Line data Source code
1 : /*
2 : * Purpose: Test check dbcolinfo/dbtableinfo information
3 : * Functions: dbresults dbsqlexec dbtablecolinfo
4 : */
5 :
6 : #include "common.h"
7 :
8 : static int failed = 0;
9 :
10 : static void
11 60 : check_is(const char *value, const char *expected)
12 : {
13 60 : if (strcmp(value, expected) == 0)
14 : return;
15 :
16 0 : failed = 1;
17 0 : fprintf(stderr, "Wrong value, got \"%s\" expected \"%s\"\n", value, expected);
18 : }
19 :
20 : static void
21 30 : check_contains(const char *value, const char *expected)
22 : {
23 30 : if (strstr(value, expected) != NULL)
24 : return;
25 :
26 0 : failed = 1;
27 0 : fprintf(stderr, "Wrong value, got \"%s\" expected to contains \"%s\"\n", value, expected);
28 : }
29 :
30 10 : TEST_MAIN()
31 : {
32 : LOGINREC *login;
33 : DBPROCESS *dbproc;
34 : int n_col;
35 : DBCOL2 col2;
36 :
37 10 : set_malloc_options();
38 :
39 10 : read_login_info(argc, argv);
40 :
41 10 : printf("Starting %s\n", argv[0]);
42 :
43 10 : dbinit();
44 :
45 10 : dberrhandle(syb_err_handler);
46 10 : dbmsghandle(syb_msg_handler);
47 :
48 10 : printf("About to logon\n");
49 :
50 10 : login = dblogin();
51 10 : DBSETLPWD(login, PASSWORD);
52 10 : DBSETLUSER(login, USER);
53 10 : DBSETLAPP(login, "colinfo");
54 :
55 10 : printf("About to open\n");
56 :
57 10 : dbproc = dbopen(login, SERVER);
58 10 : if (strlen(DATABASE))
59 10 : dbuse(dbproc, DATABASE);
60 10 : dbloginfree(login);
61 :
62 10 : printf("creating tables\n");
63 10 : sql_cmd(dbproc);
64 10 : dbsqlexec(dbproc);
65 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
66 : /* nop */
67 : }
68 :
69 10 : sql_cmd(dbproc); /* select */
70 10 : dbsqlexec(dbproc);
71 :
72 10 : if (dbresults(dbproc) != SUCCEED) {
73 0 : printf("Was expecting a result set.");
74 0 : exit(1);
75 : }
76 :
77 30 : for (n_col = 1; n_col <= 3; ++n_col) {
78 30 : col2.SizeOfStruct = sizeof(col2);
79 30 : if (dbtablecolinfo(dbproc, n_col, (DBCOL *) &col2) != SUCCEED) {
80 0 : fprintf(stderr, "dbtablecolinfo failed for col %d\n", n_col);
81 0 : failed = 1;
82 0 : continue;
83 : }
84 :
85 30 : if (n_col == 1) {
86 10 : check_is(col2.Name, "number");
87 10 : check_is(col2.ActualName, "is_an_int");
88 10 : check_contains(col2.TableName, "#colinfo_table");
89 20 : } else if (n_col == 2) {
90 10 : check_is(col2.Name, "is_a_string");
91 10 : check_is(col2.ActualName, "is_a_string");
92 10 : check_contains(col2.TableName, "#colinfo_table");
93 : } else if (n_col == 3) {
94 10 : check_is(col2.Name, "dollars");
95 10 : check_is(col2.ActualName, "is_a_money");
96 10 : check_contains(col2.TableName, "#test_table");
97 : }
98 : }
99 :
100 10 : dbexit();
101 :
102 10 : printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
103 10 : return failed ? 1 : 0;
104 : }
|