xref: /PHP-8.0/ext/oci8/tests/bug51291_1.phpt (revision 58a65c4b)
1--TEST--
2Bug #51291 (oci_error() doesn't report last error when called two times)
3--SKIPIF--
4<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?>
5--FILE--
6<?php
7
8require(__DIR__.'/connect.inc');
9
10echo "Test 1 - Parse\n";
11
12$s = @oci_parse($c, "select ' from dual");
13if (!$s) {
14    var_dump(oci_error($c));
15    echo "2nd call\n";
16    var_dump(oci_error($c));
17}
18
19echo "\nTest 2 - Parse\n";
20
21$s = @oci_parse($c, "select ' from dual");
22if (!$s) {
23    var_dump(oci_error(), oci_error($c));
24    echo "2nd call\n";
25    var_dump(oci_error(), oci_error($c));
26}
27
28echo "\nTest 3 - Execute\n";
29
30$s = @oci_parse($c, 'select doesnotexist from dual');
31$r = @oci_execute($s, OCI_DEFAULT);
32if (!$r) {
33    var_dump(oci_error($s));
34    echo "2nd call\n";
35    var_dump(oci_error($s));
36}
37
38echo "\nTest 4 - Execute - consecutive oci_error calls of different kinds\n";
39
40$s = @oci_parse($c, 'select doesnotexist from dual');
41$r = @oci_execute($s, OCI_DEFAULT);
42if (!$r) {
43    var_dump(oci_error(), oci_error($c), oci_error($s));
44    echo "2nd call\n";
45    var_dump(oci_error(), oci_error($c), oci_error($s));
46}
47
48
49echo "\nTest 5 - Execute - after oci_rollback\n";
50
51$s = @oci_parse($c, 'select doesnotexist from dual');
52$r = @oci_execute($s, OCI_DEFAULT);
53if (!$r) {
54    var_dump(oci_error(), oci_error($c), oci_error($s));
55    $r = oci_rollback($c);
56    echo "Rollback status is ";
57    if (is_null($r)) echo "null";
58    else if ($r === false) echo "false";
59    else if ($r === true) echo "true";
60    else echo $r;
61    echo "\n";
62    echo "2nd call after oci_rollback\n";
63    var_dump(oci_error(), oci_error($c), oci_error($s));
64}
65
66
67echo "\nTest 6 - Execute - after successful 2nd query with new handle\n";
68
69$s = @oci_parse($c, 'select doesnotexist from dual');
70$r = @oci_execute($s, OCI_DEFAULT);
71if (!$r) {
72    var_dump(oci_error(), oci_error($c), oci_error($s));
73    $s2 = oci_parse($c, 'select 1 from dual');
74    $r = oci_execute($s2, OCI_DEFAULT);
75    echo "Execute status is ";
76    if (is_null($r)) echo "null";
77    else if ($r === false) echo "false";
78    else if ($r === true) echo "true";
79    else echo $r;
80    echo "\n";
81    echo "2nd call after successful execute\n";
82    var_dump(oci_error(), oci_error($c), oci_error($s), oci_error($s2));
83}
84
85
86echo "\nTest 7 - Execute - after successful 2nd query with same handle\n";
87
88$s = @oci_parse($c, 'select doesnotexist from dual');
89$r = @oci_execute($s, OCI_DEFAULT);
90if (!$r) {
91    var_dump(oci_error(), oci_error($c), oci_error($s));
92    $s = oci_parse($c, 'select 1 from dual');
93    $r = oci_execute($s, OCI_DEFAULT);
94    echo "Execute status is ";
95    if (is_null($r)) echo "null";
96    else if ($r === false) echo "false";
97    else if ($r === true) echo "true";
98    else echo $r;
99    echo "\n";
100    echo "2nd call after successful execute\n";
101    var_dump(oci_error(), oci_error($c), oci_error($s));
102}
103
104
105echo "\nTest 8 - Execute - after unsuccessful 2nd query with new handle\n";
106
107$s = @oci_parse($c, 'select doesnotexist from dual');
108$r = @oci_execute($s, OCI_DEFAULT);
109if (!$r) {
110    var_dump(oci_error(), oci_error($c), oci_error($s));
111    $s2 = oci_parse($c, 'select reallynothere from dual');
112    $r = oci_execute($s2, OCI_DEFAULT);
113    echo "Execute status is ";
114    if (is_null($r)) echo "null";
115    else if ($r === false) echo "false";
116    else if ($r === true) echo "true";
117    else echo $r;
118    echo "\n";
119    echo "2nd call after unsuccessful execute\n";
120    var_dump(oci_error(), oci_error($c), oci_error($s), oci_error($s2));
121}
122
123echo "\nTest 9 - Execute - after unsuccessful 2nd query with same handle\n";
124
125$s = @oci_parse($c, 'select doesnotexist from dual');
126$r = @oci_execute($s, OCI_DEFAULT);
127if (!$r) {
128    var_dump(oci_error(), oci_error($c), oci_error($s));
129    $s = oci_parse($c, 'select reallynothere from dual');
130    $r = oci_execute($s, OCI_DEFAULT);
131    echo "Execute status is ";
132    if (is_null($r)) echo "null";
133    else if ($r === false) echo "false";
134    else if ($r === true) echo "true";
135    else echo $r;
136    echo "\n";
137    echo "2nd call after unsuccessful execute\n";
138    var_dump(oci_error(), oci_error($c), oci_error($s));
139}
140
141?>
142--EXPECTF--
143Test 1 - Parse
144array(4) {
145  ["code"]=>
146  int(1756)
147  ["message"]=>
148  string(48) "ORA-01756: %s"
149  ["offset"]=>
150  int(0)
151  ["sqltext"]=>
152  string(0) ""
153}
1542nd call
155array(4) {
156  ["code"]=>
157  int(1756)
158  ["message"]=>
159  string(48) "ORA-01756: %s"
160  ["offset"]=>
161  int(0)
162  ["sqltext"]=>
163  string(0) ""
164}
165
166Test 2 - Parse
167bool(false)
168array(4) {
169  ["code"]=>
170  int(1756)
171  ["message"]=>
172  string(48) "ORA-01756: %s"
173  ["offset"]=>
174  int(0)
175  ["sqltext"]=>
176  string(0) ""
177}
1782nd call
179bool(false)
180array(4) {
181  ["code"]=>
182  int(1756)
183  ["message"]=>
184  string(48) "ORA-01756: %s"
185  ["offset"]=>
186  int(0)
187  ["sqltext"]=>
188  string(0) ""
189}
190
191Test 3 - Execute
192array(4) {
193  ["code"]=>
194  int(904)
195  ["message"]=>
196  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
197  ["offset"]=>
198  int(%d)
199  ["sqltext"]=>
200  string(29) "select doesnotexist from dual"
201}
2022nd call
203array(4) {
204  ["code"]=>
205  int(904)
206  ["message"]=>
207  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
208  ["offset"]=>
209  int(%d)
210  ["sqltext"]=>
211  string(29) "select doesnotexist from dual"
212}
213
214Test 4 - Execute - consecutive oci_error calls of different kinds
215bool(false)
216bool(false)
217array(4) {
218  ["code"]=>
219  int(904)
220  ["message"]=>
221  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
222  ["offset"]=>
223  int(%d)
224  ["sqltext"]=>
225  string(29) "select doesnotexist from dual"
226}
2272nd call
228bool(false)
229bool(false)
230array(4) {
231  ["code"]=>
232  int(904)
233  ["message"]=>
234  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
235  ["offset"]=>
236  int(%d)
237  ["sqltext"]=>
238  string(29) "select doesnotexist from dual"
239}
240
241Test 5 - Execute - after oci_rollback
242bool(false)
243bool(false)
244array(4) {
245  ["code"]=>
246  int(904)
247  ["message"]=>
248  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
249  ["offset"]=>
250  int(%d)
251  ["sqltext"]=>
252  string(29) "select doesnotexist from dual"
253}
254Rollback status is true
2552nd call after oci_rollback
256bool(false)
257bool(false)
258array(4) {
259  ["code"]=>
260  int(904)
261  ["message"]=>
262  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
263  ["offset"]=>
264  int(%d)
265  ["sqltext"]=>
266  string(29) "select doesnotexist from dual"
267}
268
269Test 6 - Execute - after successful 2nd query with new handle
270bool(false)
271bool(false)
272array(4) {
273  ["code"]=>
274  int(904)
275  ["message"]=>
276  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
277  ["offset"]=>
278  int(%d)
279  ["sqltext"]=>
280  string(29) "select doesnotexist from dual"
281}
282Execute status is true
2832nd call after successful execute
284bool(false)
285bool(false)
286array(4) {
287  ["code"]=>
288  int(904)
289  ["message"]=>
290  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
291  ["offset"]=>
292  int(%d)
293  ["sqltext"]=>
294  string(29) "select doesnotexist from dual"
295}
296bool(false)
297
298Test 7 - Execute - after successful 2nd query with same handle
299bool(false)
300bool(false)
301array(4) {
302  ["code"]=>
303  int(904)
304  ["message"]=>
305  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
306  ["offset"]=>
307  int(%d)
308  ["sqltext"]=>
309  string(29) "select doesnotexist from dual"
310}
311Execute status is true
3122nd call after successful execute
313bool(false)
314bool(false)
315bool(false)
316
317Test 8 - Execute - after unsuccessful 2nd query with new handle
318bool(false)
319bool(false)
320array(4) {
321  ["code"]=>
322  int(904)
323  ["message"]=>
324  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
325  ["offset"]=>
326  int(%d)
327  ["sqltext"]=>
328  string(29) "select doesnotexist from dual"
329}
330
331Warning: oci_execute(): ORA-00904: %sREALLYNOTHERE%s in %sbug51291_1.php on line %d
332Execute status is false
3332nd call after unsuccessful execute
334bool(false)
335bool(false)
336array(4) {
337  ["code"]=>
338  int(904)
339  ["message"]=>
340  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
341  ["offset"]=>
342  int(%d)
343  ["sqltext"]=>
344  string(29) "select doesnotexist from dual"
345}
346array(4) {
347  ["code"]=>
348  int(904)
349  ["message"]=>
350  string(%d) "ORA-00904%sREALLYNOTHERE%s"
351  ["offset"]=>
352  int(%d)
353  ["sqltext"]=>
354  string(30) "select reallynothere from dual"
355}
356
357Test 9 - Execute - after unsuccessful 2nd query with same handle
358bool(false)
359bool(false)
360array(4) {
361  ["code"]=>
362  int(904)
363  ["message"]=>
364  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
365  ["offset"]=>
366  int(%d)
367  ["sqltext"]=>
368  string(29) "select doesnotexist from dual"
369}
370
371Warning: oci_execute(): ORA-00904: %sREALLYNOTHERE%s in %sbug51291_1.php on line %d
372Execute status is false
3732nd call after unsuccessful execute
374bool(false)
375bool(false)
376array(4) {
377  ["code"]=>
378  int(904)
379  ["message"]=>
380  string(%d) "ORA-00904%sREALLYNOTHERE%s"
381  ["offset"]=>
382  int(%d)
383  ["sqltext"]=>
384  string(30) "select reallynothere from dual"
385}
386