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