1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
--TEST--
Prefetch with REF cursor. Test No 2
--SKIPIF--
<?php if (!extension_loaded('oci8')) die("skip no oci8 extension");
if (!extension_loaded('oci8')) die("skip no oci8 extension");
require(dirname(__FILE__)."/connect.inc");
ob_start();
phpinfo(INFO_MODULES);
$phpinfo = ob_get_clean();
$iv = preg_match('/Oracle .*Version => (11\.2|12\.)/', $phpinfo);
if ($iv == 1) {
$sv = oci_server_version($c);
$sv = preg_match('/Release 1[012]\./', $sv, $matches);
if ($sv != 1) {
die ("skip expected output only valid when using Oracle 10g or greater server");
}
}
else {
die ("skip expected output only valid when using Oracle 11.1 or greater client");
}
?>
--FILE--
<?php
require dirname(__FILE__)."/connect.inc";
// Creates the necessary package and tables.
$stmtarray = array(
"DROP TABLE refcurtest",
"CREATE TABLE refcurtest (c1 NUMBER, c2 VARCHAR(20))",
"CREATE or REPLACE PACKAGE refcurpkg is
type refcursortype is ref cursor;
procedure open_ref_cur(cur1 out refcursortype);
procedure fetch_ref_cur(cur1 in refcursortype, c1 out number,c2 out varchar2);
end refcurpkg;",
"CREATE or REPLACE PACKAGE body refcurpkg is
procedure open_ref_cur(cur1 out refcursortype) is
begin
open cur1 for select * from refcurtest order by c1;
end open_ref_cur;
procedure fetch_ref_cur(cur1 in refcursortype, c1 out number,
c2 out varchar2) is
begin
fetch cur1 into c1,c2;
end fetch_ref_cur;
end refcurpkg;"
);
foreach($stmtarray as $stmt) {
$s = oci_parse($c,$stmt);
$r = @oci_execute($s);
if (!$r) {
$msg = oci_error($s);
if ($msg['code'] != 942) {
echo $msg['message'],"\n";
}
}
}
// Insert 500 rows into the table.
$insert_sql = "INSERT INTO refcurtest (c1, c2) VALUES (:c1,:c2)";
if (!($s = oci_parse($c, $insert_sql))) {
die("oci_parse(insert) failed!\n");
}
for ($i = 0; $i <= 500; $i++) {
$val2 = 'test'.$i;
oci_bind_by_name($s,':c1',$i);
oci_bind_by_name($s,':c2',$val2);
if (!oci_execute($s)) {
die("oci_execute(insert) failed!\n");
}
}
// Steps to Fetch from PHP . For every sub-test,the cursor is bound and then executed.
$sql1 = "begin refcurpkg.open_ref_cur(:cur1); end;";
$s1 = oci_parse($c,$sql1);
$cur1 = oci_new_cursor($c);
if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql1) failed!\n");
}
// Steps to Fetch from PL/SQL . For every sub-test,the cursor is bound and then executed.
$sql2 = "begin refcurpkg.fetch_ref_cur(:curs1,:c1,:c2); end;";
$s2 = oci_parse($c,$sql2);
if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql2) failed!\n");
}
if (!oci_bind_by_name($s2,":c1",$c1,SQLT_INT)) {
die("oci_bind_by_name(sql2) failed!\n");
}
if (!oci_bind_by_name($s2,":c2",$c2,SQLT_AFC)) {
die("oci_bind_by_name(sql2) failed!\n");
}
echo "------Test 1- Check Roundtrips with prefetch 0 and 5 -----------\n";
oci_execute($s1);
oci_execute($cur1);
$initial_rt = print_roundtrips($c);
oci_set_prefetch($cur1,0);
for ($i = 0;$i<5;$i++) {
var_dump(oci_fetch_row($cur1));
}
$cnt = (print_roundtrips($c) - $initial_rt);
echo "Number of roundtrips made with prefetch count 0 for 5 rows is $cnt\n";
$initial_rt = print_roundtrips($c);
oci_set_prefetch($cur1,5);
for ($i = 0;$i<5;$i++) {
var_dump(oci_fetch_row($cur1));
}
$cnt = (print_roundtrips($c) - $initial_rt );
echo "Number of roundtrips made with prefetch count 5 for 5 rows is $cnt\n";
echo "------Test 2 - Set Prefetch before PL/SQL fetch ----------\n";
// Fetch from PHP
$cur1 = oci_new_cursor($c);
if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql1) failed!\n");
}
echo "Fetch Row from PHP\n";
oci_execute($s1);
oci_execute($cur1);
var_dump(oci_fetch_row($cur1));
oci_set_prefetch($cur1,5);
// Fetch from PL/SQL
if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql2) failed!\n");
}
oci_execute($s2);
echo "Fetch Row from PL/SQL\n";
var_dump($c1);
var_dump($c2);
echo "------Test 3 - Set Prefetch after PL/SQL fetch ----------\n";
$cur1 = oci_new_cursor($c);
// Fetch from PL/SQL
if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql2) failed!\n");
}
oci_execute($s2);
echo "Fetch Row from PL/SQL\n";
var_dump($c1);
var_dump($c2);
// Fetch from PHP
echo "Fetch Row from PHP\n";
if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql1) failed!\n");
}
oci_set_prefetch($cur1,5);
oci_execute($s1);
oci_execute($cur1);
var_dump(oci_fetch_row($cur1));
echo "------Test 4- Overwrite prefetch-----------\n";
// Fetch from PHP
$cur1 = oci_new_cursor($c);
if (!oci_bind_by_name($s1,":cur1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql1) failed!\n");
}
echo "Fetch Row from PHP\n";
oci_execute($s1);
oci_execute($cur1);
var_dump(oci_fetch_row($cur1));
oci_set_prefetch($cur1,5);
oci_set_prefetch($cur1,0);
oci_set_prefetch($cur1,100);
// Fetch from PL/SQL
if (!oci_bind_by_name($s2,":curs1",$cur1,-1,SQLT_RSET)) {
die("oci_bind_by_name(sql2) failed!\n");
}
oci_execute($s2);
echo "Fetch Row from PL/SQL\n";
var_dump($c1);
var_dump($c2);
function print_roundtrips($c) {
$sql_stmt = "select value from v\$mystat a,v\$statname c where
a.statistic#=c.statistic# and c.name='SQL*Net roundtrips to/from client'";
$s = oci_parse($c,$sql_stmt);
oci_define_by_name($s,"VALUE",$value);
oci_execute($s);
oci_fetch($s);
return $value;
}
// Clean up here
$stmtarray = array(
"drop package refcurpkg",
"drop table refcurtest"
);
foreach($stmtarray as $stmt) {
$s = oci_parse($c,$stmt);
$r = @oci_execute($s);
if (!$r) {
$msg = oci_error($s);
echo $msg['message'],"\n";
}
}
oci_close($c);
echo "Done\n";
?>
--EXPECTF--
------Test 1- Check Roundtrips with prefetch 0 and 5 -----------
array(2) {
[0]=>
%unicode|string%(%d) "0"
[1]=>
%unicode|string%(%d) "test0"
}
array(2) {
[0]=>
%unicode|string%(%d) "1"
[1]=>
%unicode|string%(%d) "test1"
}
array(2) {
[0]=>
%unicode|string%(%d) "2"
[1]=>
%unicode|string%(%d) "test2"
}
array(2) {
[0]=>
%unicode|string%(%d) "3"
[1]=>
%unicode|string%(%d) "test3"
}
array(2) {
[0]=>
%unicode|string%(%d) "4"
[1]=>
%unicode|string%(%d) "test4"
}
Number of roundtrips made with prefetch count 0 for 5 rows is 6
array(2) {
[0]=>
%unicode|string%(%d) "5"
[1]=>
%unicode|string%(%d) "test5"
}
array(2) {
[0]=>
%unicode|string%(%d) "6"
[1]=>
%unicode|string%(%d) "test6"
}
array(2) {
[0]=>
%unicode|string%(%d) "7"
[1]=>
%unicode|string%(%d) "test7"
}
array(2) {
[0]=>
%unicode|string%(%d) "8"
[1]=>
%unicode|string%(%d) "test8"
}
array(2) {
[0]=>
%unicode|string%(%d) "9"
[1]=>
%unicode|string%(%d) "test9"
}
Number of roundtrips made with prefetch count 5 for 5 rows is 2
------Test 2 - Set Prefetch before PL/SQL fetch ----------
Fetch Row from PHP
array(2) {
[0]=>
%unicode|string%(%d) "0"
[1]=>
%unicode|string%(%d) "test0"
}
Fetch Row from PL/SQL
%unicode|string%(%d) "101"
%unicode|string%(%d) "test101"
------Test 3 - Set Prefetch after PL/SQL fetch ----------
Warning: oci_execute(): ORA-01001: %s
ORA-06512: at "SYSTEM.REFCURPKG", line %d
ORA-06512: at line %d in %s on line %d
Fetch Row from PL/SQL
%unicode|string%(%d) "101"
%unicode|string%(%d) "test101"
Fetch Row from PHP
array(2) {
[0]=>
%unicode|string%(%d) "0"
[1]=>
%unicode|string%(%d) "test0"
}
------Test 4- Overwrite prefetch-----------
Fetch Row from PHP
array(2) {
[0]=>
%unicode|string%(%d) "0"
[1]=>
%unicode|string%(%d) "test0"
}
Fetch Row from PL/SQL
%unicode|string%(%d) "101"
%unicode|string%(%d) "test101"
Done
|