xref: /PHP-8.1/ext/oci8/tests/bug38173.phpt (revision b5a14e6c)
1--TEST--
2Bug #38173 (Freeing nested cursors causes OCI8 to segfault)
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9?>
10--FILE--
11<?php
12
13require __DIR__."/connect.inc";
14
15$create_1 = "CREATE TABLE t1 (id INTEGER)";
16$create_2 = "CREATE TABLE t2 (id INTEGER)";
17$drop_1 = "DROP TABLE t1";
18$drop_2 = "DROP TABLE t2";
19
20$s1 = oci_parse($c, $drop_1);
21$s2 = oci_parse($c, $drop_2);
22@oci_execute($s1);
23@oci_execute($s2);
24
25$s1 = oci_parse($c, $create_1);
26$s2 = oci_parse($c, $create_2);
27oci_execute($s1);
28oci_execute($s2);
29
30for($i=0; $i < 5; $i++) {
31    $insert = "INSERT INTO t1 VALUES(".$i.")";
32    $s = oci_parse($c, $insert);
33    oci_execute($s);
34}
35
36for($i=0; $i < 5; $i++) {
37    $insert = "INSERT INTO t2 VALUES(".$i.")";
38    $s = oci_parse($c, $insert);
39    oci_execute($s);
40}
41
42$query ="
43SELECT
44  t1.*,
45  CURSOR( SELECT * FROM t2 ) as cursor
46FROM
47  t1
48";
49
50$sth = oci_parse($c, $query);
51oci_execute($sth);
52
53// dies on oci_free_statement on 2nd pass through loop
54while ( $row = oci_fetch_assoc($sth) ) {
55  print "Got row!\n";
56  var_dump(oci_execute($row['CURSOR']));
57  var_dump(oci_free_statement($row['CURSOR']));
58}
59
60$s1 = oci_parse($c, $drop_1);
61$s2 = oci_parse($c, $drop_2);
62@oci_execute($s1);
63@oci_execute($s2);
64
65echo "Done\n";
66
67?>
68--EXPECT--
69Got row!
70bool(true)
71bool(true)
72Got row!
73bool(true)
74bool(true)
75Got row!
76bool(true)
77bool(true)
78Got row!
79bool(true)
80bool(true)
81Got row!
82bool(true)
83bool(true)
84Done
85