xref: /PHP-7.2/ext/oci8/tests/bug51291_1.phpt (revision 3d497f88)
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(dirname(__FILE__).'/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), oci_error($s));
24    echo "2nd call\n";
25    var_dump(oci_error(), oci_error($c), oci_error($s));
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===DONE===
143<?php exit(0); ?>
144--EXPECTF--
145Test 1 - Parse
146array(4) {
147  ["code"]=>
148  int(1756)
149  ["message"]=>
150  string(48) "ORA-01756: %s"
151  ["offset"]=>
152  int(0)
153  ["sqltext"]=>
154  string(0) ""
155}
1562nd call
157array(4) {
158  ["code"]=>
159  int(1756)
160  ["message"]=>
161  string(48) "ORA-01756: %s"
162  ["offset"]=>
163  int(0)
164  ["sqltext"]=>
165  string(0) ""
166}
167
168Test 2 - Parse
169
170Warning: oci_error() expects parameter 1 to be resource, bool%sgiven in %sbug51291_1.php on line %d
171bool(false)
172array(4) {
173  ["code"]=>
174  int(1756)
175  ["message"]=>
176  string(48) "ORA-01756: %s"
177  ["offset"]=>
178  int(0)
179  ["sqltext"]=>
180  string(0) ""
181}
182NULL
1832nd call
184
185Warning: oci_error() expects parameter 1 to be resource, bool%sgiven in %sbug51291_1.php on line %d
186bool(false)
187array(4) {
188  ["code"]=>
189  int(1756)
190  ["message"]=>
191  string(48) "ORA-01756: %s"
192  ["offset"]=>
193  int(0)
194  ["sqltext"]=>
195  string(0) ""
196}
197NULL
198
199Test 3 - Execute
200array(4) {
201  ["code"]=>
202  int(904)
203  ["message"]=>
204  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
205  ["offset"]=>
206  int(%d)
207  ["sqltext"]=>
208  string(29) "select doesnotexist from dual"
209}
2102nd call
211array(4) {
212  ["code"]=>
213  int(904)
214  ["message"]=>
215  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
216  ["offset"]=>
217  int(%d)
218  ["sqltext"]=>
219  string(29) "select doesnotexist from dual"
220}
221
222Test 4 - Execute - consecutive oci_error calls of different kinds
223bool(false)
224bool(false)
225array(4) {
226  ["code"]=>
227  int(904)
228  ["message"]=>
229  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
230  ["offset"]=>
231  int(%d)
232  ["sqltext"]=>
233  string(29) "select doesnotexist from dual"
234}
2352nd call
236bool(false)
237bool(false)
238array(4) {
239  ["code"]=>
240  int(904)
241  ["message"]=>
242  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
243  ["offset"]=>
244  int(%d)
245  ["sqltext"]=>
246  string(29) "select doesnotexist from dual"
247}
248
249Test 5 - Execute - after oci_rollback
250bool(false)
251bool(false)
252array(4) {
253  ["code"]=>
254  int(904)
255  ["message"]=>
256  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
257  ["offset"]=>
258  int(%d)
259  ["sqltext"]=>
260  string(29) "select doesnotexist from dual"
261}
262Rollback status is true
2632nd call after oci_rollback
264bool(false)
265bool(false)
266array(4) {
267  ["code"]=>
268  int(904)
269  ["message"]=>
270  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
271  ["offset"]=>
272  int(%d)
273  ["sqltext"]=>
274  string(29) "select doesnotexist from dual"
275}
276
277Test 6 - Execute - after successful 2nd query with new handle
278bool(false)
279bool(false)
280array(4) {
281  ["code"]=>
282  int(904)
283  ["message"]=>
284  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
285  ["offset"]=>
286  int(%d)
287  ["sqltext"]=>
288  string(29) "select doesnotexist from dual"
289}
290Execute status is true
2912nd call after successful execute
292bool(false)
293bool(false)
294array(4) {
295  ["code"]=>
296  int(904)
297  ["message"]=>
298  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
299  ["offset"]=>
300  int(%d)
301  ["sqltext"]=>
302  string(29) "select doesnotexist from dual"
303}
304bool(false)
305
306Test 7 - Execute - after successful 2nd query with same handle
307bool(false)
308bool(false)
309array(4) {
310  ["code"]=>
311  int(904)
312  ["message"]=>
313  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
314  ["offset"]=>
315  int(%d)
316  ["sqltext"]=>
317  string(29) "select doesnotexist from dual"
318}
319Execute status is true
3202nd call after successful execute
321bool(false)
322bool(false)
323bool(false)
324
325Test 8 - Execute - after unsuccessful 2nd query with new handle
326bool(false)
327bool(false)
328array(4) {
329  ["code"]=>
330  int(904)
331  ["message"]=>
332  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
333  ["offset"]=>
334  int(%d)
335  ["sqltext"]=>
336  string(29) "select doesnotexist from dual"
337}
338
339Warning: oci_execute(): ORA-00904: %sREALLYNOTHERE%s in %sbug51291_1.php on line %d
340Execute status is false
3412nd call after unsuccessful execute
342bool(false)
343bool(false)
344array(4) {
345  ["code"]=>
346  int(904)
347  ["message"]=>
348  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
349  ["offset"]=>
350  int(%d)
351  ["sqltext"]=>
352  string(29) "select doesnotexist from dual"
353}
354array(4) {
355  ["code"]=>
356  int(904)
357  ["message"]=>
358  string(%d) "ORA-00904%sREALLYNOTHERE%s"
359  ["offset"]=>
360  int(%d)
361  ["sqltext"]=>
362  string(30) "select reallynothere from dual"
363}
364
365Test 9 - Execute - after unsuccessful 2nd query with same handle
366bool(false)
367bool(false)
368array(4) {
369  ["code"]=>
370  int(904)
371  ["message"]=>
372  string(%d) "ORA-00904:%sDOESNOTEXIST%s"
373  ["offset"]=>
374  int(%d)
375  ["sqltext"]=>
376  string(29) "select doesnotexist from dual"
377}
378
379Warning: oci_execute(): ORA-00904: %sREALLYNOTHERE%s in %sbug51291_1.php on line %d
380Execute status is false
3812nd call after unsuccessful execute
382bool(false)
383bool(false)
384array(4) {
385  ["code"]=>
386  int(904)
387  ["message"]=>
388  string(%d) "ORA-00904%sREALLYNOTHERE%s"
389  ["offset"]=>
390  int(%d)
391  ["sqltext"]=>
392  string(30) "select reallynothere from dual"
393}
394===DONE===
395