Line data Source code
1 : /*
2 : * Purpose: Test binding of string types
3 : * Functions: dbbind dbcmd dbcolname dbnextrow dbnumcols dbopen dbresults dbsqlexec
4 :
5 : */
6 :
7 : #include "common.h"
8 :
9 : static int failed = 0;
10 :
11 : static void insert_row(DBPROCESS * dbproc);
12 : static int select_rows(DBPROCESS * dbproc, int bind_type);
13 :
14 : int
15 10 : main(int argc, char **argv)
16 : {
17 : LOGINREC *login;
18 : DBPROCESS *dbproc;
19 :
20 10 : read_login_info(argc, argv);
21 10 : printf("Starting %s\n", argv[0]);
22 :
23 10 : dbinit();
24 :
25 10 : printf("About to logon\n");
26 :
27 10 : login = dblogin();
28 10 : DBSETLPWD(login, PASSWORD);
29 10 : DBSETLUSER(login, USER);
30 10 : DBSETLAPP(login, "t0011");
31 :
32 10 : printf("About to open\n");
33 :
34 10 : dbproc = dbopen(login, SERVER);
35 10 : if (strlen(DATABASE))
36 10 : dbuse(dbproc, DATABASE);
37 10 : dbloginfree(login);
38 :
39 10 : printf("Dropping table\n");
40 10 : sql_cmd(dbproc);
41 10 : dbsqlexec(dbproc);
42 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
43 : /* nop */
44 : }
45 :
46 10 : printf("creating table\n");
47 10 : sql_cmd(dbproc);
48 10 : dbsqlexec(dbproc);
49 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
50 : /* nop */
51 : }
52 :
53 10 : printf("insert\n");
54 :
55 10 : insert_row(dbproc);
56 10 : insert_row(dbproc);
57 10 : insert_row(dbproc);
58 :
59 10 : failed = select_rows(dbproc, STRINGBIND);
60 :
61 10 : dbexit();
62 :
63 10 : printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
64 10 : return failed ? 1 : 0;
65 : }
66 :
67 : static int
68 10 : select_rows(DBPROCESS * dbproc, int bind_type)
69 : {
70 : char teststr[1024];
71 : char teststr2[1024];
72 : char testvstr[1024];
73 : DBINT testint;
74 : DBINT i;
75 :
76 :
77 10 : printf("select\n");
78 10 : sql_cmd(dbproc);
79 10 : dbsqlexec(dbproc);
80 :
81 :
82 10 : if (dbresults(dbproc) != SUCCEED) {
83 0 : failed = 1;
84 0 : printf("Was expecting a result set.");
85 0 : exit(1);
86 : }
87 :
88 40 : for (i = 1; i <= dbnumcols(dbproc); i++) {
89 40 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
90 : }
91 :
92 10 : if (SUCCEED != dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint)) {
93 0 : fprintf(stderr, "Had problem with bind\n");
94 0 : return 1;
95 : }
96 10 : if (SUCCEED != dbbind(dbproc, 2, bind_type, 0, (BYTE *) teststr)) {
97 0 : fprintf(stderr, "Had problem with bind\n");
98 0 : return 1;
99 : }
100 10 : if (SUCCEED != dbbind(dbproc, 3, bind_type, 0, (BYTE *) teststr2)) {
101 0 : fprintf(stderr, "Had problem with bind\n");
102 0 : return 1;
103 : }
104 10 : if (SUCCEED != dbbind(dbproc, 4, bind_type, 0, (BYTE *) testvstr)) {
105 0 : fprintf(stderr, "Had problem with bind\n");
106 0 : return 1;
107 : }
108 :
109 : i = 0;
110 40 : while (dbnextrow(dbproc) == REG_ROW) {
111 30 : i++;
112 30 : if (testint != i) {
113 0 : printf("Failed. Expected i to be |%d|, was |%d|\n", testint, i);
114 0 : return 1;
115 : }
116 30 : printf("c: %s$\n", teststr);
117 30 : printf("c2: %s$\n", teststr2);
118 30 : printf("vc: %s$\n", testvstr);
119 : if (bind_type == STRINGBIND) {
120 : } else {
121 : }
122 : }
123 : return 0;
124 : }
125 :
126 : static void
127 30 : insert_row(DBPROCESS * dbproc)
128 : {
129 30 : sql_cmd(dbproc);
130 30 : dbsqlexec(dbproc);
131 30 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
132 : /* nop */
133 : }
134 30 : }
|