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