1--TEST-- 2Bug #42841 (REF CURSOR and oci_new_cursor PHP crash) 3--SKIPIF-- 4<?php 5$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs 6require(dirname(__FILE__).'/skipif.inc'); 7?> 8--INI-- 9oci8.statement_cache_size=20 10--FILE-- 11<?php 12 13require dirname(__FILE__).'/details.inc'; 14 15// note a oci_new_connect() occurs lower in the script 16$c = oci_connect($user, $password, $dbase); 17 18// Initialization 19 20$stmtarray = array( 21 "create or replace procedure bug42841_proc(out_1 out sys_refcursor) is 22 begin 23 open out_1 for select 11 from dual union all select 12 from dual union all select 13 from dual; 24 end bug42841_proc;", 25 26 "create or replace package bug43449_pkg is 27 type cursortype is ref Cursor; 28 function testcursor return cursortype; 29 end bug43449_pkg;", 30 31 "create or replace package body bug43449_pkg is 32 function testcursor return cursortype is 33 retCursor cursorType; 34 begin 35 Open retCursor For 'select * from dual'; 36 return retCursor; 37 end; 38 end bug43449_pkg;" 39); 40 41oci8_test_sql_execute($c, $stmtarray); 42 43// Main code 44 45function do_bug42841($c) 46{ 47 echo "First attempt\n"; 48 49 $sql = "BEGIN bug42841_proc(:cursor); END;"; 50 $stmt = oci_parse($c, $sql); 51 $cursor = oci_new_cursor($c); 52 oci_bind_by_name($stmt, ":cursor", $cursor, -1, OCI_B_CURSOR); 53 54 oci_execute($stmt, OCI_DEFAULT); 55 oci_execute($cursor); 56 57 while($row = oci_fetch_array($cursor, OCI_ASSOC + OCI_RETURN_LOBS)) { 58 $data1[] = $row; 59 } 60 61 oci_free_statement($stmt); 62 oci_free_statement($cursor); 63 var_dump($data1); 64 65 echo "Second attempt\n"; 66 67 $sql = "BEGIN bug42841_proc(:cursor); END;"; 68 $stmt = oci_parse($c, $sql); 69 $cursor = oci_new_cursor($c); 70 oci_bind_by_name($stmt, ":cursor", $cursor, -1, OCI_B_CURSOR); 71 72 oci_execute($stmt, OCI_DEFAULT); 73 oci_execute($cursor); 74 75 while($row = oci_fetch_array($cursor, OCI_ASSOC + OCI_RETURN_LOBS)) { 76 $data2[] = $row; 77 } 78 79 oci_free_statement($stmt); 80 oci_free_statement($cursor); 81 var_dump($data2); 82} 83 84function do_bug43449($c) 85{ 86 87 for ($i = 0; $i < 2; $i++) { 88 var_dump(bug43449_getCur($c)); 89 } 90} 91 92function bug43449_getCur($c) 93{ 94 $cur = oci_new_cursor($c); 95 $stmt = oci_parse($c, 'begin :cur := bug43449_pkg.testcursor; end;'); 96 oci_bind_by_name($stmt, ':cur', $cur, -1, OCI_B_CURSOR); 97 oci_execute($stmt, OCI_DEFAULT); 98 oci_execute($cur, OCI_DEFAULT); 99 100 $ret = array(); 101 102 while (ocifetchinto($cur, $row, OCI_ASSOC)) { 103 $ret[] = $row; 104 } 105 106 oci_free_statement($cur); 107 oci_free_statement($stmt); 108 return $ret; 109} 110 111echo "Test bug 42841: Procedure with OUT cursor parameter\n"; 112do_bug42841($c); 113 114$c = oci_new_connect($user, $password, $dbase); 115 116echo "Test bug 43449: Cursor as function result\n"; 117do_bug43449($c); 118 119// Cleanup 120 121$stmtarray = array( 122 "drop procedure bug42841_proc", 123 "drop package bug43449_pkg" 124); 125 126oci8_test_sql_execute($c, $stmtarray); 127 128echo "Done\n"; 129 130?> 131--EXPECT-- 132Test bug 42841: Procedure with OUT cursor parameter 133First attempt 134array(3) { 135 [0]=> 136 array(1) { 137 [11]=> 138 string(2) "11" 139 } 140 [1]=> 141 array(1) { 142 [11]=> 143 string(2) "12" 144 } 145 [2]=> 146 array(1) { 147 [11]=> 148 string(2) "13" 149 } 150} 151Second attempt 152array(3) { 153 [0]=> 154 array(1) { 155 [11]=> 156 string(2) "11" 157 } 158 [1]=> 159 array(1) { 160 [11]=> 161 string(2) "12" 162 } 163 [2]=> 164 array(1) { 165 [11]=> 166 string(2) "13" 167 } 168} 169Test bug 43449: Cursor as function result 170array(1) { 171 [0]=> 172 array(1) { 173 ["DUMMY"]=> 174 string(1) "X" 175 } 176} 177array(1) { 178 [0]=> 179 array(1) { 180 ["DUMMY"]=> 181 string(1) "X" 182 } 183} 184Done 185