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