xref: /PHP-8.0/ext/oci8/tests/imp_res_1.phpt (revision a555cc0b)
1--TEST--
2Oracle Database 12c Implicit Result Sets: basic test
3--SKIPIF--
4<?php
5if (!extension_loaded('oci8')) die ("skip no oci8 extension");
6$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
7require(__DIR__.'/skipif.inc');
8preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
9if (!(isset($matches[0]) && $matches[1] >= 12)) {
10    die("skip expected output only valid when using Oracle Database 12c or greater");
11}
12preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
13if (!(isset($matches[0]) && $matches[0] >= 12)) {
14    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
15}
16?>
17--FILE--
18<?php
19
20require(__DIR__.'/connect.inc');
21
22// Initialization
23
24$stmtarray = array(
25    "drop table imp_res_1_tab_1",
26    "create table imp_res_1_tab_1 (c1 number, c2 varchar2(10))",
27    "insert into imp_res_1_tab_1 values (1, 'abcde')",
28    "insert into imp_res_1_tab_1 values (2, 'fghij')",
29    "insert into imp_res_1_tab_1 values (3, 'klmno')",
30
31    "drop table imp_res_1_tab_2",
32    "create table imp_res_1_tab_2 (c3 varchar2(1))",
33    "insert into imp_res_1_tab_2 values ('t')",
34    "insert into imp_res_1_tab_2 values ('u')",
35    "insert into imp_res_1_tab_2 values ('v')",
36
37    "create or replace procedure imp_res_1_proc as
38      c1 sys_refcursor;
39    begin
40      open c1 for select * from imp_res_1_tab_1 order by 1;
41      dbms_sql.return_result(c1);
42
43      open c1 for select * from imp_res_1_tab_2 where rownum < 3 order by 1;
44      dbms_sql.return_result(c1);
45
46      open c1 for select 99 from dual;
47      dbms_sql.return_result (c1);
48
49      open c1 for select NULL, 'Z' from dual;
50      dbms_sql.return_result (c1);
51
52      open c1 for select * from imp_res_1_tab_1 order by 1;
53      dbms_sql.return_result(c1);
54    end;"
55);
56
57oci8_test_sql_execute($c, $stmtarray);
58
59// Run Test
60
61echo "Test 1 - oci_fetch_assoc\n";
62$s = oci_parse($c, "begin imp_res_1_proc(); end;");
63oci_execute($s);
64while (($row = oci_fetch_assoc($s)) != false)
65    var_dump($row);
66
67echo "\nTest 2 - oci_fetch_object\n";
68$s = oci_parse($c, "begin imp_res_1_proc(); end;");
69oci_execute($s);
70while (($row = oci_fetch_object($s)) != false)
71    var_dump($row);
72
73echo "\nTest 3 - oci_fetch_row\n";
74$s = oci_parse($c, "begin imp_res_1_proc(); end;");
75oci_execute($s);
76while (($row = oci_fetch_row($s)) != false)
77    var_dump($row);
78
79echo "\nTest 4 - oci_fetch_array(OCI_ASSOC+OCI_RETURN_NULLS)\n";
80$s = oci_parse($c, "begin imp_res_1_proc(); end;");
81oci_execute($s);
82while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false)
83    var_dump($row);
84
85echo "\nTest 5 - oci_fetch_array(OCI_ASSOC)\n";
86$s = oci_parse($c, "begin imp_res_1_proc(); end;");
87oci_execute($s);
88while (($row = oci_fetch_array($s, OCI_ASSOC)) != false)
89    var_dump($row);
90
91echo "\nTest 6 - oci_fetch_array(OCI_NUM)\n";
92$s = oci_parse($c, "begin imp_res_1_proc(); end;");
93oci_execute($s);
94while (($row = oci_fetch_array($s, OCI_NUM)) != false)
95    var_dump($row);
96
97echo "\nTest 7 - oci_fetch_array(OCI_BOTH)\n";
98$s = oci_parse($c, "begin imp_res_1_proc(); end;");
99oci_execute($s);
100while (($row = oci_fetch_array($s, OCI_BOTH)) != false)
101    var_dump($row);
102
103echo "\nTest 8 - oci_fetch_array(OCI_BOTH+OCI_RETURN_NULLS)\n";
104$s = oci_parse($c, "begin imp_res_1_proc(); end;");
105oci_execute($s);
106while (($row = oci_fetch_array($s, OCI_BOTH+OCI_RETURN_NULLS)) != false)
107    var_dump($row);
108
109// Clean up
110
111$stmtarray = array(
112    "drop procedure imp_res_1_proc",
113    "drop table imp_res_1_tab_1",
114    "drop table imp_res_1_tab_2"
115);
116
117oci8_test_sql_execute($c, $stmtarray);
118
119?>
120--EXPECTF--
121Test 1 - oci_fetch_assoc
122array(2) {
123  ["C1"]=>
124  string(1) "1"
125  ["C2"]=>
126  string(5) "abcde"
127}
128array(2) {
129  ["C1"]=>
130  string(1) "2"
131  ["C2"]=>
132  string(5) "fghij"
133}
134array(2) {
135  ["C1"]=>
136  string(1) "3"
137  ["C2"]=>
138  string(5) "klmno"
139}
140array(1) {
141  ["C3"]=>
142  string(1) "t"
143}
144array(1) {
145  ["C3"]=>
146  string(1) "u"
147}
148array(1) {
149  [99]=>
150  string(2) "99"
151}
152array(2) {
153  ["NULL"]=>
154  NULL
155  ["'Z'"]=>
156  string(1) "Z"
157}
158array(2) {
159  ["C1"]=>
160  string(1) "1"
161  ["C2"]=>
162  string(5) "abcde"
163}
164array(2) {
165  ["C1"]=>
166  string(1) "2"
167  ["C2"]=>
168  string(5) "fghij"
169}
170array(2) {
171  ["C1"]=>
172  string(1) "3"
173  ["C2"]=>
174  string(5) "klmno"
175}
176
177Test 2 - oci_fetch_object
178object(stdClass)#%d (2) {
179  ["C1"]=>
180  string(1) "1"
181  ["C2"]=>
182  string(5) "abcde"
183}
184object(stdClass)#%d (2) {
185  ["C1"]=>
186  string(1) "2"
187  ["C2"]=>
188  string(5) "fghij"
189}
190object(stdClass)#%d (2) {
191  ["C1"]=>
192  string(1) "3"
193  ["C2"]=>
194  string(5) "klmno"
195}
196object(stdClass)#%d (1) {
197  ["C3"]=>
198  string(1) "t"
199}
200object(stdClass)#%d (1) {
201  ["C3"]=>
202  string(1) "u"
203}
204object(stdClass)#%d (1) {
205  [99]=>
206  string(2) "99"
207}
208object(stdClass)#%d (2) {
209  ["NULL"]=>
210  NULL
211  ["'Z'"]=>
212  string(1) "Z"
213}
214object(stdClass)#%d (2) {
215  ["C1"]=>
216  string(1) "1"
217  ["C2"]=>
218  string(5) "abcde"
219}
220object(stdClass)#%d (2) {
221  ["C1"]=>
222  string(1) "2"
223  ["C2"]=>
224  string(5) "fghij"
225}
226object(stdClass)#%d (2) {
227  ["C1"]=>
228  string(1) "3"
229  ["C2"]=>
230  string(5) "klmno"
231}
232
233Test 3 - oci_fetch_row
234array(2) {
235  [0]=>
236  string(1) "1"
237  [1]=>
238  string(5) "abcde"
239}
240array(2) {
241  [0]=>
242  string(1) "2"
243  [1]=>
244  string(5) "fghij"
245}
246array(2) {
247  [0]=>
248  string(1) "3"
249  [1]=>
250  string(5) "klmno"
251}
252array(1) {
253  [0]=>
254  string(1) "t"
255}
256array(1) {
257  [0]=>
258  string(1) "u"
259}
260array(1) {
261  [0]=>
262  string(2) "99"
263}
264array(2) {
265  [0]=>
266  NULL
267  [1]=>
268  string(1) "Z"
269}
270array(2) {
271  [0]=>
272  string(1) "1"
273  [1]=>
274  string(5) "abcde"
275}
276array(2) {
277  [0]=>
278  string(1) "2"
279  [1]=>
280  string(5) "fghij"
281}
282array(2) {
283  [0]=>
284  string(1) "3"
285  [1]=>
286  string(5) "klmno"
287}
288
289Test 4 - oci_fetch_array(OCI_ASSOC+OCI_RETURN_NULLS)
290array(2) {
291  ["C1"]=>
292  string(1) "1"
293  ["C2"]=>
294  string(5) "abcde"
295}
296array(2) {
297  ["C1"]=>
298  string(1) "2"
299  ["C2"]=>
300  string(5) "fghij"
301}
302array(2) {
303  ["C1"]=>
304  string(1) "3"
305  ["C2"]=>
306  string(5) "klmno"
307}
308array(1) {
309  ["C3"]=>
310  string(1) "t"
311}
312array(1) {
313  ["C3"]=>
314  string(1) "u"
315}
316array(1) {
317  [99]=>
318  string(2) "99"
319}
320array(2) {
321  ["NULL"]=>
322  NULL
323  ["'Z'"]=>
324  string(1) "Z"
325}
326array(2) {
327  ["C1"]=>
328  string(1) "1"
329  ["C2"]=>
330  string(5) "abcde"
331}
332array(2) {
333  ["C1"]=>
334  string(1) "2"
335  ["C2"]=>
336  string(5) "fghij"
337}
338array(2) {
339  ["C1"]=>
340  string(1) "3"
341  ["C2"]=>
342  string(5) "klmno"
343}
344
345Test 5 - oci_fetch_array(OCI_ASSOC)
346array(2) {
347  ["C1"]=>
348  string(1) "1"
349  ["C2"]=>
350  string(5) "abcde"
351}
352array(2) {
353  ["C1"]=>
354  string(1) "2"
355  ["C2"]=>
356  string(5) "fghij"
357}
358array(2) {
359  ["C1"]=>
360  string(1) "3"
361  ["C2"]=>
362  string(5) "klmno"
363}
364array(1) {
365  ["C3"]=>
366  string(1) "t"
367}
368array(1) {
369  ["C3"]=>
370  string(1) "u"
371}
372array(1) {
373  [99]=>
374  string(2) "99"
375}
376array(1) {
377  ["'Z'"]=>
378  string(1) "Z"
379}
380array(2) {
381  ["C1"]=>
382  string(1) "1"
383  ["C2"]=>
384  string(5) "abcde"
385}
386array(2) {
387  ["C1"]=>
388  string(1) "2"
389  ["C2"]=>
390  string(5) "fghij"
391}
392array(2) {
393  ["C1"]=>
394  string(1) "3"
395  ["C2"]=>
396  string(5) "klmno"
397}
398
399Test 6 - oci_fetch_array(OCI_NUM)
400array(2) {
401  [0]=>
402  string(1) "1"
403  [1]=>
404  string(5) "abcde"
405}
406array(2) {
407  [0]=>
408  string(1) "2"
409  [1]=>
410  string(5) "fghij"
411}
412array(2) {
413  [0]=>
414  string(1) "3"
415  [1]=>
416  string(5) "klmno"
417}
418array(1) {
419  [0]=>
420  string(1) "t"
421}
422array(1) {
423  [0]=>
424  string(1) "u"
425}
426array(1) {
427  [0]=>
428  string(2) "99"
429}
430array(1) {
431  [1]=>
432  string(1) "Z"
433}
434array(2) {
435  [0]=>
436  string(1) "1"
437  [1]=>
438  string(5) "abcde"
439}
440array(2) {
441  [0]=>
442  string(1) "2"
443  [1]=>
444  string(5) "fghij"
445}
446array(2) {
447  [0]=>
448  string(1) "3"
449  [1]=>
450  string(5) "klmno"
451}
452
453Test 7 - oci_fetch_array(OCI_BOTH)
454array(4) {
455  [0]=>
456  string(1) "1"
457  ["C1"]=>
458  string(1) "1"
459  [1]=>
460  string(5) "abcde"
461  ["C2"]=>
462  string(5) "abcde"
463}
464array(4) {
465  [0]=>
466  string(1) "2"
467  ["C1"]=>
468  string(1) "2"
469  [1]=>
470  string(5) "fghij"
471  ["C2"]=>
472  string(5) "fghij"
473}
474array(4) {
475  [0]=>
476  string(1) "3"
477  ["C1"]=>
478  string(1) "3"
479  [1]=>
480  string(5) "klmno"
481  ["C2"]=>
482  string(5) "klmno"
483}
484array(2) {
485  [0]=>
486  string(1) "t"
487  ["C3"]=>
488  string(1) "t"
489}
490array(2) {
491  [0]=>
492  string(1) "u"
493  ["C3"]=>
494  string(1) "u"
495}
496array(2) {
497  [0]=>
498  string(2) "99"
499  [99]=>
500  string(2) "99"
501}
502array(2) {
503  [1]=>
504  string(1) "Z"
505  ["'Z'"]=>
506  string(1) "Z"
507}
508array(4) {
509  [0]=>
510  string(1) "1"
511  ["C1"]=>
512  string(1) "1"
513  [1]=>
514  string(5) "abcde"
515  ["C2"]=>
516  string(5) "abcde"
517}
518array(4) {
519  [0]=>
520  string(1) "2"
521  ["C1"]=>
522  string(1) "2"
523  [1]=>
524  string(5) "fghij"
525  ["C2"]=>
526  string(5) "fghij"
527}
528array(4) {
529  [0]=>
530  string(1) "3"
531  ["C1"]=>
532  string(1) "3"
533  [1]=>
534  string(5) "klmno"
535  ["C2"]=>
536  string(5) "klmno"
537}
538
539Test 8 - oci_fetch_array(OCI_BOTH+OCI_RETURN_NULLS)
540array(4) {
541  [0]=>
542  string(1) "1"
543  ["C1"]=>
544  string(1) "1"
545  [1]=>
546  string(5) "abcde"
547  ["C2"]=>
548  string(5) "abcde"
549}
550array(4) {
551  [0]=>
552  string(1) "2"
553  ["C1"]=>
554  string(1) "2"
555  [1]=>
556  string(5) "fghij"
557  ["C2"]=>
558  string(5) "fghij"
559}
560array(4) {
561  [0]=>
562  string(1) "3"
563  ["C1"]=>
564  string(1) "3"
565  [1]=>
566  string(5) "klmno"
567  ["C2"]=>
568  string(5) "klmno"
569}
570array(2) {
571  [0]=>
572  string(1) "t"
573  ["C3"]=>
574  string(1) "t"
575}
576array(2) {
577  [0]=>
578  string(1) "u"
579  ["C3"]=>
580  string(1) "u"
581}
582array(2) {
583  [0]=>
584  string(2) "99"
585  [99]=>
586  string(2) "99"
587}
588array(4) {
589  [0]=>
590  NULL
591  ["NULL"]=>
592  NULL
593  [1]=>
594  string(1) "Z"
595  ["'Z'"]=>
596  string(1) "Z"
597}
598array(4) {
599  [0]=>
600  string(1) "1"
601  ["C1"]=>
602  string(1) "1"
603  [1]=>
604  string(5) "abcde"
605  ["C2"]=>
606  string(5) "abcde"
607}
608array(4) {
609  [0]=>
610  string(1) "2"
611  ["C1"]=>
612  string(1) "2"
613  [1]=>
614  string(5) "fghij"
615  ["C2"]=>
616  string(5) "fghij"
617}
618array(4) {
619  [0]=>
620  string(1) "3"
621  ["C1"]=>
622  string(1) "3"
623  [1]=>
624  string(5) "klmno"
625  ["C2"]=>
626  string(5) "klmno"
627}
628