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