bug38173.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. --TEST--
  2. Bug #38173 (Freeing nested cursors causes OCI8 to segfault)
  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. $create_1 = "CREATE TABLE t1 (id INTEGER)";
  14. $create_2 = "CREATE TABLE t2 (id INTEGER)";
  15. $drop_1 = "DROP TABLE t1";
  16. $drop_2 = "DROP TABLE t2";
  17. $s1 = oci_parse($c, $drop_1);
  18. $s2 = oci_parse($c, $drop_2);
  19. @oci_execute($s1);
  20. @oci_execute($s2);
  21. $s1 = oci_parse($c, $create_1);
  22. $s2 = oci_parse($c, $create_2);
  23. oci_execute($s1);
  24. oci_execute($s2);
  25. for($i=0; $i < 5; $i++) {
  26. $insert = "INSERT INTO t1 VALUES(".$i.")";
  27. $s = oci_parse($c, $insert);
  28. oci_execute($s);
  29. }
  30. for($i=0; $i < 5; $i++) {
  31. $insert = "INSERT INTO t2 VALUES(".$i.")";
  32. $s = oci_parse($c, $insert);
  33. oci_execute($s);
  34. }
  35. $query ="
  36. SELECT
  37. t1.*,
  38. CURSOR( SELECT * FROM t2 ) as cursor
  39. FROM
  40. t1
  41. ";
  42. $sth = oci_parse($c, $query);
  43. oci_execute($sth);
  44. // dies on oci_free_statement on 2nd pass through loop
  45. while ( $row = oci_fetch_assoc($sth) ) {
  46. print "Got row!\n";
  47. var_dump(oci_execute($row['CURSOR']));
  48. var_dump(oci_free_statement($row['CURSOR']));
  49. }
  50. $s1 = oci_parse($c, $drop_1);
  51. $s2 = oci_parse($c, $drop_2);
  52. @oci_execute($s1);
  53. @oci_execute($s2);
  54. echo "Done\n";
  55. ?>
  56. --EXPECT--
  57. Got row!
  58. bool(true)
  59. bool(true)
  60. Got row!
  61. bool(true)
  62. bool(true)
  63. Got row!
  64. bool(true)
  65. bool(true)
  66. Got row!
  67. bool(true)
  68. bool(true)
  69. Got row!
  70. bool(true)
  71. bool(true)
  72. Done