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