Line data Source code
1 : /*
2 : * Purpose: this will test what is returned from a batch of queries that do not return any rows
3 : * This is related to a bug first identified in PHPs PDO library https://bugs.php.net/bug.php?id=72969
4 : * Functions: dbbind dbcmd dbcolname dberrhandle dbisopt dbmsghandle dbnextrow dbnumcols dbopen dbresults dbsetlogintime dbsqlexec dbuse
5 : */
6 :
7 : #include "common.h"
8 :
9 : int
10 8 : main(int argc, char **argv)
11 : {
12 : LOGINREC *login;
13 : DBPROCESS *dbproc;
14 : int i;
15 : DBINT erc;
16 :
17 : RETCODE ret;
18 : int rowcount;
19 : int colcount;
20 :
21 8 : set_malloc_options();
22 :
23 8 : read_login_info(argc, argv);
24 8 : if (argc > 1) {
25 0 : argc -= optind;
26 0 : argv += optind;
27 : }
28 :
29 8 : printf("Starting %s\n", argv[0]);
30 :
31 : /* Fortify_EnterScope(); */
32 8 : dbinit();
33 :
34 8 : dberrhandle(syb_err_handler);
35 8 : dbmsghandle(syb_msg_handler);
36 :
37 8 : printf("About to logon as \"%s\"\n", USER);
38 :
39 8 : login = dblogin();
40 8 : DBSETLPWD(login, PASSWORD);
41 8 : DBSETLUSER(login, USER);
42 8 : DBSETLAPP(login, "batch_stmt_ins_upd");
43 :
44 8 : if (argc > 1) {
45 0 : printf("server and login timeout overrides (%s and %s) detected\n", argv[0], argv[1]);
46 0 : strcpy(SERVER, argv[0]);
47 0 : i = atoi(argv[1]);
48 0 : if (i) {
49 0 : i = dbsetlogintime(i);
50 0 : printf("dbsetlogintime returned %s.\n", (i == SUCCEED) ? "SUCCEED" : "FAIL");
51 : }
52 : }
53 :
54 8 : printf("About to open \"%s\"\n", SERVER);
55 :
56 8 : dbproc = dbopen(login, SERVER);
57 8 : if (!dbproc) {
58 0 : fprintf(stderr, "Unable to connect to %s\n", SERVER);
59 0 : return 1;
60 : }
61 8 : dbloginfree(login);
62 :
63 8 : printf("Using database \"%s\"\n", DATABASE);
64 8 : if (strlen(DATABASE)) {
65 8 : erc = dbuse(dbproc, DATABASE);
66 8 : assert(erc == SUCCEED);
67 : }
68 :
69 8 : sql_cmd(dbproc);
70 8 : dbsqlexec(dbproc);
71 8 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
72 : /* nop */
73 : }
74 :
75 : /*
76 : * This test is written to simulate how dblib is used in PDO
77 : * functions are called in the same order they would be if doing
78 : * PDO::query followed by some number of PDO::statement->nextRowset
79 : */
80 :
81 : /*
82 : * First, call everything that happens in PDO::query
83 : * this will return the results of the CREATE TABLE statement
84 : */
85 8 : dbcancel(dbproc);
86 :
87 8 : printf("using sql_cmd\n");
88 8 : sql_cmd(dbproc);
89 8 : dbsqlexec(dbproc);
90 :
91 8 : ret = dbresults(dbproc);
92 8 : rowcount = DBCOUNT(dbproc);
93 8 : colcount = dbnumcols(dbproc);
94 :
95 8 : printf("RETCODE: %d\n", ret);
96 8 : printf("ROWCOUNT: %d\n", rowcount);
97 8 : printf("COLCOUNT: %d\n\n", colcount);
98 :
99 : /* check the results of the create table statement */
100 8 : assert(ret == SUCCEED);
101 8 : assert(rowcount == -1);
102 8 : assert(colcount == 0);
103 :
104 : /* now simulate calling nextRowset() for each remaining statement in our batch */
105 :
106 : /*
107 : * INSERT
108 : */
109 8 : ret = dbnextrow(dbproc);
110 8 : assert(ret == NO_MORE_ROWS);
111 :
112 8 : ret = dbresults(dbproc);
113 8 : rowcount = DBCOUNT(dbproc);
114 8 : colcount = dbnumcols(dbproc);
115 :
116 8 : printf("RETCODE: %d\n", ret);
117 8 : printf("ROWCOUNT: %d\n", rowcount);
118 8 : printf("COLCOUNT: %d\n\n", colcount);
119 :
120 8 : assert(ret == SUCCEED);
121 8 : assert(rowcount == 3);
122 8 : assert(colcount == 0);
123 :
124 : /*
125 : * UPDATE
126 : */
127 8 : ret = dbnextrow(dbproc);
128 8 : assert(ret == NO_MORE_ROWS);
129 :
130 8 : ret = dbresults(dbproc);
131 8 : rowcount = DBCOUNT(dbproc);
132 8 : colcount = dbnumcols(dbproc);
133 :
134 8 : printf("RETCODE: %d\n", ret);
135 8 : printf("ROWCOUNT: %d\n", rowcount);
136 8 : printf("COLCOUNT: %d\n\n", colcount);
137 :
138 8 : assert(ret == SUCCEED);
139 8 : assert(rowcount == 3);
140 8 : assert(colcount == 0);
141 :
142 : /*
143 : * INSERT
144 : */
145 8 : ret = dbnextrow(dbproc);
146 8 : assert(ret == NO_MORE_ROWS);
147 :
148 8 : ret = dbresults(dbproc);
149 8 : rowcount = DBCOUNT(dbproc);
150 8 : colcount = dbnumcols(dbproc);
151 :
152 8 : printf("RETCODE: %d\n", ret);
153 8 : printf("ROWCOUNT: %d\n", rowcount);
154 8 : printf("COLCOUNT: %d\n\n", colcount);
155 :
156 8 : assert(ret == SUCCEED);
157 8 : assert(rowcount == 1);
158 8 : assert(colcount == 0);
159 :
160 : /*
161 : * DROP
162 : */
163 8 : ret = dbnextrow(dbproc);
164 8 : assert(ret == NO_MORE_ROWS);
165 :
166 8 : ret = dbresults(dbproc);
167 8 : rowcount = DBCOUNT(dbproc);
168 8 : colcount = dbnumcols(dbproc);
169 :
170 8 : printf("RETCODE: %d\n", ret);
171 8 : printf("ROWCOUNT: %d\n", rowcount);
172 8 : printf("COLCOUNT: %d\n\n", colcount);
173 :
174 8 : assert(ret == SUCCEED);
175 8 : assert(rowcount == -1);
176 8 : assert(colcount == 0);
177 :
178 : /* Call one more time to be sure we get NO_MORE_RESULTS */
179 8 : ret = dbnextrow(dbproc);
180 8 : assert(ret == NO_MORE_ROWS);
181 :
182 8 : ret = dbresults(dbproc);
183 8 : rowcount = DBCOUNT(dbproc);
184 8 : colcount = dbnumcols(dbproc);
185 :
186 8 : printf("RETCODE: %d\n", ret);
187 8 : printf("ROWCOUNT: %d\n", rowcount);
188 8 : printf("COLCOUNT: %d\n\n", colcount);
189 :
190 8 : assert(ret == NO_MORE_RESULTS);
191 8 : assert(rowcount == -1);
192 8 : assert(colcount == 0);
193 :
194 8 : dbexit();
195 :
196 8 : printf("%s OK\n", __FILE__);
197 8 : return 0;
198 : }
|