1--TEST--
2Prefetch with Nested cursors with INI setting.
3--INI--
4oci8.default_prefetch=5
5--EXTENSIONS--
6oci8
7--SKIPIF--
8<?php
9require_once 'skipifconnectfailure.inc';
10require __DIR__.'/connect.inc';
11preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
12if (!(isset($matches[0]) &&
13      (($matches[1] == 11 && $matches[2] >= 2) ||
14       ($matches[1] >= 12)
15       ))) {
16        die("skip expected output only valid when using Oracle 11gR2 or greater database server");
17}
18preg_match('/^([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/', oci_client_version(), $matches);
19if (!(isset($matches[0]) &&
20    (($matches[1] == 11 && $matches[2] >= 2) ||
21     ($matches[1] >= 12)
22     ))) {
23    die("skip test expected to work only with Oracle 11gR2 or greater version of client");
24}
25?>
26--FILE--
27<?php
28require __DIR__."/connect.inc";
29
30//Create tables here
31$stmtarray = array(
32    "drop table nescurtest",
33    "create table nescurtest(c1 varchar2(10))"
34);
35
36oci8_test_sql_execute($c, $stmtarray);
37
38// Insert 500 rows into the table.
39$insert_sql = "INSERT INTO nescurtest (c1) VALUES (:c1)";
40if (!($s = oci_parse($c, $insert_sql))) {
41    die("oci_parse(insert) failed!\n");
42}
43
44for ($i = 0; $i<=500; $i++) {
45    $val2 = 'test'.$i;
46    oci_bind_by_name($s,':c1',$val2);
47    if (!oci_execute($s)) {
48        die("oci_execute(insert) failed!\n");
49    }
50}
51
52echo"-----------------------------------------------\n";
53echo "Test with Nested Cursors\n";
54echo"-----------------------------------------------\n";
55$cur1 = oci_new_cursor($c);
56$sqlstmt = "select cursor(select * from nescurtest) curs1 from dual";
57$s = oci_parse($c,$sqlstmt);
58oci_execute($s);
59$data = oci_fetch_array($s);
60oci_execute($data['CURS1']);
61
62// Calculate round-trips
63$initial_rt = print_roundtrips($c);
64for ($i = 0;$i<10;$i++) {
65    echo "Fetch Row using Nested cursor Query\n";
66    var_dump(oci_fetch_row($data['CURS1']));
67}
68
69$cnt = (print_roundtrips($c) - $initial_rt);
70echo "Number of roundtrips made with prefetch count 5 for 10 rows is  $cnt\n";
71
72function  print_roundtrips($c) {
73    $sql_stmt = "select value from v\$mystat a,v\$statname c where
74         a.statistic#=c.statistic# and c.name='SQL*Net roundtrips to/from client'";
75    $s = oci_parse($c,$sql_stmt);
76    oci_define_by_name($s,"VALUE",$value);
77    oci_execute($s);
78    oci_fetch($s);
79    return $value;
80}
81
82// Clean up  here
83
84$stmtarray = array(
85    "drop table nescurtest"
86);
87
88oci8_test_sql_execute($c, $stmtarray);
89
90echo "Done\n";
91?>
92--EXPECTF--
93-----------------------------------------------
94Test with Nested Cursors
95-----------------------------------------------
96Fetch Row using Nested cursor Query
97array(1) {
98  [0]=>
99  string(%d) "test0"
100}
101Fetch Row using Nested cursor Query
102array(1) {
103  [0]=>
104  string(%d) "test1"
105}
106Fetch Row using Nested cursor Query
107array(1) {
108  [0]=>
109  string(%d) "test2"
110}
111Fetch Row using Nested cursor Query
112array(1) {
113  [0]=>
114  string(%d) "test3"
115}
116Fetch Row using Nested cursor Query
117array(1) {
118  [0]=>
119  string(%d) "test4"
120}
121Fetch Row using Nested cursor Query
122array(1) {
123  [0]=>
124  string(%d) "test5"
125}
126Fetch Row using Nested cursor Query
127array(1) {
128  [0]=>
129  string(%d) "test6"
130}
131Fetch Row using Nested cursor Query
132array(1) {
133  [0]=>
134  string(%d) "test7"
135}
136Fetch Row using Nested cursor Query
137array(1) {
138  [0]=>
139  string(%d) "test8"
140}
141Fetch Row using Nested cursor Query
142array(1) {
143  [0]=>
144  string(%d) "test9"
145}
146Number of roundtrips made with prefetch count 5 for 10 rows is  3
147Done
148