1--TEST-- 2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: get from wrong statement 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 23function print_row($row) 24{ 25 foreach ($row as $item) { 26 echo " ".$item; 27 } 28 echo "\n"; 29} 30 31$plsql = 32 "declare 33 c1 sys_refcursor; 34 begin 35 open c1 for select 1 from dual union all select 2 from dual; 36 dbms_sql.return_result(c1); 37 open c1 for select 3 from dual union all select 4 from dual; 38 dbms_sql.return_result(c1); 39 open c1 for select 5 from dual union all select 6 from dual; 40 dbms_sql.return_result(c1); 41 end;"; 42 43// Run Test 44 45echo "Test 1\n"; 46// This test effectively discards all the first IRS results 47$s = oci_parse($c, $plsql); 48oci_execute($s); 49while (($s1 = oci_get_implicit_resultset($s))) { // $s1 is never used again so its results are lost 50 while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) { // use parent $s instead of $s1 51 print_row($row); 52 } 53} 54oci_free_statement($s); 55 56echo "\nTest 2 - fetch first IRS explicitly\n"; 57$s = oci_parse($c, $plsql); 58oci_execute($s); 59$s1 = oci_get_implicit_resultset($s); 60while (($row = oci_fetch_row($s1)) != false) { 61 print_row($row); 62} 63while (($row = oci_fetch_row($s)) != false) { 64 print_row($row); 65} 66oci_free_statement($s); 67 68echo "\nTest 3 - fetch part of IRS explicitly\n"; 69$s = oci_parse($c, $plsql); 70oci_execute($s); 71$s1 = oci_get_implicit_resultset($s); 72while (($row = oci_fetch_row($s1)) != false) { 73 print_row($row); 74} 75$row = oci_fetch_row($s); 76print_row($row); 77$s1 = oci_get_implicit_resultset($s); 78while (($row = oci_fetch_row($s1)) != false) { 79 print_row($row); 80} 81while (($row = oci_fetch_row($s)) != false) { 82 print_row($row); 83} 84oci_free_statement($s); 85 86echo "\nTest 4 - skip IRSs\n"; 87$s = oci_parse($c, $plsql); 88oci_execute($s); 89$s1 = oci_get_implicit_resultset($s); 90$s1 = oci_get_implicit_resultset($s); 91while (($row = oci_fetch_row($s)) != false) { // parent 92 print_row($row); 93} 94oci_free_statement($s); 95 96?> 97--EXPECT-- 98Test 1 99 3 100 4 101 5 102 6 103 104Test 2 - fetch first IRS explicitly 105 1 106 2 107 3 108 4 109 5 110 6 111 112Test 3 - fetch part of IRS explicitly 113 1 114 2 115 3 116 5 117 6 118 4 119 120Test 4 - skip IRSs 121 5 122 6 123