refcur_prefetch_3.phpt 3.4 KB

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