bug40415.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. --TEST--
  2. Bug #40415 (Using oci_fetchall with nested cursors)
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. ?>
  10. --FILE--
  11. <?php
  12. require __DIR__."/connect.inc";
  13. // Setup
  14. $create_1 = "CREATE TABLE t1 (id1 INTEGER)";
  15. $create_2 = "CREATE TABLE t2 (id2 INTEGER)";
  16. $drop_1 = "DROP TABLE t1";
  17. $drop_2 = "DROP TABLE t2";
  18. $s1 = oci_parse($c, $drop_1);
  19. $s2 = oci_parse($c, $drop_2);
  20. @oci_execute($s1);
  21. @oci_execute($s2);
  22. $s1 = oci_parse($c, $create_1);
  23. $s2 = oci_parse($c, $create_2);
  24. oci_execute($s1);
  25. oci_execute($s2);
  26. for($i=1; $i < 4; $i++) {
  27. $insert = "INSERT INTO t1 VALUES(1".$i.")";
  28. $s = oci_parse($c, $insert);
  29. oci_execute($s);
  30. }
  31. for($i=1; $i < 4; $i++) {
  32. $insert = "INSERT INTO t2 VALUES(2".$i.")";
  33. $s = oci_parse($c, $insert);
  34. oci_execute($s);
  35. }
  36. function do_assoc($c)
  37. {
  38. $query = "SELECT t1.*, CURSOR( SELECT * FROM t2 ) AS CURSOR FROM t1";
  39. $stmt = oci_parse($c, $query);
  40. oci_execute($stmt);
  41. while ($row = oci_fetch_assoc($stmt)) {
  42. print "Got row \"".$row['ID1']."\". Now getting nested cursor:\n";
  43. var_dump(oci_execute($row['CURSOR']));
  44. while ($row_n = oci_fetch_assoc($row['CURSOR']) ) {
  45. var_dump($row_n);
  46. }
  47. }
  48. }
  49. function do_all($c)
  50. {
  51. $query = "SELECT t1.*, CURSOR( SELECT * FROM t2 ) AS CURSOR FROM t1";
  52. $stmt = oci_parse($c, $query);
  53. oci_execute($stmt);
  54. $rc1 = oci_fetch_all($stmt, $res);
  55. echo "Rows returned $rc1\n";
  56. var_dump($res);
  57. foreach ($res['CURSOR'] as $cv) {
  58. echo "Getting nested cursor\n";
  59. var_dump(oci_execute($cv));
  60. $rc2 = oci_fetch_all($cv, $res2);
  61. var_dump($res2);
  62. }
  63. }
  64. echo "Test 1: Associate fetch of nested cursor\n";
  65. do_assoc($c);
  66. echo "\nTest 2: fetchall of nested cursor\n";
  67. do_all($c);
  68. // Cleanup
  69. $s1 = oci_parse($c, $drop_1);
  70. $s2 = oci_parse($c, $drop_2);
  71. @oci_execute($s1);
  72. @oci_execute($s2);
  73. echo "Done\n";
  74. ?>
  75. --EXPECTF--
  76. Test 1: Associate fetch of nested cursor
  77. Got row "11". Now getting nested cursor:
  78. bool(true)
  79. array(1) {
  80. ["ID2"]=>
  81. string(2) "21"
  82. }
  83. array(1) {
  84. ["ID2"]=>
  85. string(2) "22"
  86. }
  87. array(1) {
  88. ["ID2"]=>
  89. string(2) "23"
  90. }
  91. Got row "12". Now getting nested cursor:
  92. bool(true)
  93. array(1) {
  94. ["ID2"]=>
  95. string(2) "21"
  96. }
  97. array(1) {
  98. ["ID2"]=>
  99. string(2) "22"
  100. }
  101. array(1) {
  102. ["ID2"]=>
  103. string(2) "23"
  104. }
  105. Got row "13". Now getting nested cursor:
  106. bool(true)
  107. array(1) {
  108. ["ID2"]=>
  109. string(2) "21"
  110. }
  111. array(1) {
  112. ["ID2"]=>
  113. string(2) "22"
  114. }
  115. array(1) {
  116. ["ID2"]=>
  117. string(2) "23"
  118. }
  119. Test 2: fetchall of nested cursor
  120. Rows returned 3
  121. array(2) {
  122. ["ID1"]=>
  123. array(3) {
  124. [0]=>
  125. string(2) "11"
  126. [1]=>
  127. string(2) "12"
  128. [2]=>
  129. string(2) "13"
  130. }
  131. ["CURSOR"]=>
  132. array(3) {
  133. [0]=>
  134. resource(%d) of type (oci8 statement)
  135. [1]=>
  136. resource(%d) of type (oci8 statement)
  137. [2]=>
  138. resource(%d) of type (oci8 statement)
  139. }
  140. }
  141. Getting nested cursor
  142. bool(true)
  143. array(1) {
  144. ["ID2"]=>
  145. array(3) {
  146. [0]=>
  147. string(2) "21"
  148. [1]=>
  149. string(2) "22"
  150. [2]=>
  151. string(2) "23"
  152. }
  153. }
  154. Getting nested cursor
  155. bool(true)
  156. array(1) {
  157. ["ID2"]=>
  158. array(3) {
  159. [0]=>
  160. string(2) "21"
  161. [1]=>
  162. string(2) "22"
  163. [2]=>
  164. string(2) "23"
  165. }
  166. }
  167. Getting nested cursor
  168. bool(true)
  169. array(1) {
  170. ["ID2"]=>
  171. array(3) {
  172. [0]=>
  173. string(2) "21"
  174. [1]=>
  175. string(2) "22"
  176. [2]=>
  177. string(2) "23"
  178. }
  179. }
  180. Done