bug42841.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. --TEST--
  2. Bug #42841 (REF CURSOR and oci_new_cursor PHP crash)
  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. --INI--
  11. oci8.statement_cache_size=20
  12. --FILE--
  13. <?php
  14. require __DIR__.'/details.inc';
  15. // note a oci_new_connect() occurs lower in the script
  16. $c = oci_connect($user, $password, $dbase);
  17. // Initialization
  18. $stmtarray = array(
  19. "create or replace procedure bug42841_proc(out_1 out sys_refcursor) is
  20. begin
  21. open out_1 for select 11 from dual union all select 12 from dual union all select 13 from dual;
  22. end bug42841_proc;",
  23. "create or replace package bug43449_pkg is
  24. type cursortype is ref Cursor;
  25. function testcursor return cursortype;
  26. end bug43449_pkg;",
  27. "create or replace package body bug43449_pkg is
  28. function testcursor return cursortype is
  29. retCursor cursorType;
  30. begin
  31. Open retCursor For 'select * from dual';
  32. return retCursor;
  33. end;
  34. end bug43449_pkg;"
  35. );
  36. oci8_test_sql_execute($c, $stmtarray);
  37. // Main code
  38. function do_bug42841($c)
  39. {
  40. echo "First attempt\n";
  41. $sql = "BEGIN bug42841_proc(:cursor); END;";
  42. $stmt = oci_parse($c, $sql);
  43. $cursor = oci_new_cursor($c);
  44. oci_bind_by_name($stmt, ":cursor", $cursor, -1, OCI_B_CURSOR);
  45. oci_execute($stmt, OCI_DEFAULT);
  46. oci_execute($cursor);
  47. while($row = oci_fetch_array($cursor, OCI_ASSOC + OCI_RETURN_LOBS)) {
  48. $data1[] = $row;
  49. }
  50. oci_free_statement($stmt);
  51. oci_free_statement($cursor);
  52. var_dump($data1);
  53. echo "Second attempt\n";
  54. $sql = "BEGIN bug42841_proc(:cursor); END;";
  55. $stmt = oci_parse($c, $sql);
  56. $cursor = oci_new_cursor($c);
  57. oci_bind_by_name($stmt, ":cursor", $cursor, -1, OCI_B_CURSOR);
  58. oci_execute($stmt, OCI_DEFAULT);
  59. oci_execute($cursor);
  60. while($row = oci_fetch_array($cursor, OCI_ASSOC + OCI_RETURN_LOBS)) {
  61. $data2[] = $row;
  62. }
  63. oci_free_statement($stmt);
  64. oci_free_statement($cursor);
  65. var_dump($data2);
  66. }
  67. function do_bug43449($c)
  68. {
  69. for ($i = 0; $i < 2; $i++) {
  70. var_dump(bug43449_getCur($c));
  71. }
  72. }
  73. function bug43449_getCur($c)
  74. {
  75. $cur = oci_new_cursor($c);
  76. $stmt = oci_parse($c, 'begin :cur := bug43449_pkg.testcursor; end;');
  77. oci_bind_by_name($stmt, ':cur', $cur, -1, OCI_B_CURSOR);
  78. oci_execute($stmt, OCI_DEFAULT);
  79. oci_execute($cur, OCI_DEFAULT);
  80. $ret = array();
  81. while ($row = oci_fetch_assoc($cur)) {
  82. $ret[] = $row;
  83. }
  84. oci_free_statement($cur);
  85. oci_free_statement($stmt);
  86. return $ret;
  87. }
  88. echo "Test bug 42841: Procedure with OUT cursor parameter\n";
  89. do_bug42841($c);
  90. $c = oci_new_connect($user, $password, $dbase);
  91. echo "Test bug 43449: Cursor as function result\n";
  92. do_bug43449($c);
  93. // Cleanup
  94. $stmtarray = array(
  95. "drop procedure bug42841_proc",
  96. "drop package bug43449_pkg"
  97. );
  98. oci8_test_sql_execute($c, $stmtarray);
  99. echo "Done\n";
  100. ?>
  101. --EXPECT--
  102. Test bug 42841: Procedure with OUT cursor parameter
  103. First attempt
  104. array(3) {
  105. [0]=>
  106. array(1) {
  107. [11]=>
  108. string(2) "11"
  109. }
  110. [1]=>
  111. array(1) {
  112. [11]=>
  113. string(2) "12"
  114. }
  115. [2]=>
  116. array(1) {
  117. [11]=>
  118. string(2) "13"
  119. }
  120. }
  121. Second attempt
  122. array(3) {
  123. [0]=>
  124. array(1) {
  125. [11]=>
  126. string(2) "11"
  127. }
  128. [1]=>
  129. array(1) {
  130. [11]=>
  131. string(2) "12"
  132. }
  133. [2]=>
  134. array(1) {
  135. [11]=>
  136. string(2) "13"
  137. }
  138. }
  139. Test bug 43449: Cursor as function result
  140. array(1) {
  141. [0]=>
  142. array(1) {
  143. ["DUMMY"]=>
  144. string(1) "X"
  145. }
  146. }
  147. array(1) {
  148. [0]=>
  149. array(1) {
  150. ["DUMMY"]=>
  151. string(1) "X"
  152. }
  153. }
  154. Done