1--TEST-- 2oci_define_by_name tests with REF CURSORs 3--SKIPIF-- 4<?php 5$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs 6require(dirname(__FILE__).'/skipif.inc'); 7?> 8--FILE-- 9<?php 10 11require(dirname(__FILE__).'/connect.inc'); 12 13// Initialization 14 15$stmtarray = array( 16 "drop table define6_tab", 17 "create table define6_tab (id number)", 18 "insert into define6_tab values (1)" 19); 20 21oci8_test_sql_execute($c, $stmtarray); 22 23// Run Test 24 25$sql = 26"DECLARE 27 TYPE curtype IS REF CURSOR; 28 cursor_var curtype; 29BEGIN 30 OPEN cursor_var FOR SELECT id FROM define6_tab; 31 :curs := cursor_var; 32END;"; 33 34echo "Test 1 - define last\n"; 35 36$s1 = oci_parse($c, $sql); 37$cursor1 = oci_new_cursor($c); 38oci_bind_by_name($s1, ":curs", $cursor1, -1, OCI_B_CURSOR); 39oci_execute($s1); 40oci_execute($cursor1); 41oci_define_by_name($cursor1, 'ID', $id1); 42while (oci_fetch_row($cursor1)) { 43 var_dump($id1); 44} 45 46 47echo "Test 2 - define last with preset var\n"; 48 49$s2 = oci_parse($c, $sql); 50$cursor2 = oci_new_cursor($c); 51oci_bind_by_name($s2, ":curs", $cursor2, -1, OCI_B_CURSOR); 52oci_execute($s2); 53oci_execute($cursor2); 54$id2 = ''; 55oci_define_by_name($cursor2, 'ID', $id2); 56while (oci_fetch_row($cursor2)) { 57 var_dump($id2); 58} 59 60 61echo "Test 3 - define before cursor execute\n"; 62 63$s3 = oci_parse($c, $sql); 64$cursor3 = oci_new_cursor($c); 65oci_bind_by_name($s3, ":curs", $cursor3, -1, OCI_B_CURSOR); 66oci_execute($s3); 67oci_define_by_name($cursor3, 'ID', $id3); 68oci_execute($cursor3); 69while (oci_fetch_row($cursor3)) { 70 var_dump($id3); 71} 72 73 74echo "Test 4 - define before top level execute\n"; 75 76$s4 = oci_parse($c, $sql); 77$cursor4 = oci_new_cursor($c); 78oci_bind_by_name($s4, ":curs", $cursor4, -1, OCI_B_CURSOR); 79oci_define_by_name($cursor4, 'ID', $id4); 80oci_execute($s4); 81oci_execute($cursor4); 82while (oci_fetch_row($cursor4)) { 83 var_dump($id4); 84} 85 86 87echo "Test 5 - define before bind\n"; 88 89$s5 = oci_parse($c, $sql); 90$cursor5 = oci_new_cursor($c); 91oci_define_by_name($cursor5, 'ID', $id5); 92oci_bind_by_name($s5, ":curs", $cursor5, -1, OCI_B_CURSOR); 93oci_execute($s5); 94oci_execute($cursor5); 95while (oci_fetch_row($cursor5)) { 96 var_dump($id5); 97} 98 99 100echo "Test 6 - fetch on wrong handle\n"; 101 102$s6 = oci_parse($c, $sql); 103$cursor6 = oci_new_cursor($c); 104oci_define_by_name($cursor6, 'ID', $id6); 105oci_bind_by_name($s6, ":curs", $cursor6, -1, OCI_B_CURSOR); 106oci_execute($s6); 107oci_execute($cursor6); 108while (oci_fetch_row($s6)) { 109 var_dump($id6); 110} 111 112 113// Clean up 114 115$stmtarray = array( 116 "drop table define6_tab" 117); 118 119oci8_test_sql_execute($c, $stmtarray); 120 121?> 122===DONE=== 123<?php exit(0); ?> 124--EXPECTF-- 125Test 1 - define last 126NULL 127Test 2 - define last with preset var 128string(0) "" 129Test 3 - define before cursor execute 130string(1) "1" 131Test 4 - define before top level execute 132string(1) "1" 133Test 5 - define before bind 134string(1) "1" 135Test 6 - fetch on wrong handle 136 137Warning: oci_fetch_row(): ORA-24374: %s in %sdefine6.php on line %d 138===DONE=== 139