xref: /PHP-8.3/ext/oci8/tests/bug43492.phpt (revision a53e5617)
1--TEST--
2Bug #43492 (Nested cursor leaks)
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$stmtarray = array(
17    "DROP table bug43492_tab",
18    "CREATE TABLE bug43492_tab(col1 VARCHAR2(1))",
19    "INSERT INTO bug43492_tab VALUES ('A')",
20    "INSERT INTO bug43492_tab VALUES ('B')",
21    "INSERT INTO bug43492_tab VALUES ('C')",
22    "INSERT INTO bug43492_tab VALUES ('D')",
23    "INSERT INTO bug43492_tab VALUES ('E')",
24    "INSERT INTO bug43492_tab VALUES ('F')",
25    "INSERT INTO bug43492_tab VALUES ('G')",
26    "INSERT INTO bug43492_tab VALUES ('H')",
27    "INSERT INTO bug43492_tab VALUES ('I')",
28    "INSERT INTO bug43492_tab VALUES ('J')"
29);
30
31oci8_test_sql_execute($c, $stmtarray);
32
33/*
34
35While fetching data from a ref cursor, the parent statement needs to
36be around.  Also when the parent statement goes out of scope, it is
37not automatically released which causes a cursor leak.
38
39If either or both of the lines marked (*) are removed, then the script
40will fail with the error "ORA-01000: maximum open cursors exceeded".
41
42*/
43
44function fetch($c, $i) {
45    global $s;   //  (*) Allow parent statement to be available when child is used
46    $s = oci_parse($c, 'select cursor(select * from bug43492_tab) c from bug43492_tab');
47    oci_execute($s, OCI_DEFAULT);
48    $result = oci_fetch_assoc($s);
49    oci_execute($result['C'], OCI_DEFAULT);
50    return $result['C'];
51}
52
53for($i = 0; $i < 300; $i++) {
54    $cur = fetch($c, $i);
55    for($j = 0; $j < 10; $j++) {
56        $row = oci_fetch_row($cur);
57        echo "$row[0] ";
58    }
59    echo "\n";
60    oci_free_statement($cur);
61    oci_free_statement($s);   // (*) Free the parent statement cleanly
62}
63
64echo "Done\n";
65
66// Cleanup
67
68$stmtarray = array(
69    "DROP table bug43492_tab"
70);
71
72oci8_test_sql_execute($c, $stmtarray);
73
74?>
75--EXPECT--
76A B C D E F G H I J
77A B C D E F G H I J
78A B C D E F G H I J
79A B C D E F G H I J
80A B C D E F G H I J
81A B C D E F G H I J
82A B C D E F G H I J
83A B C D E F G H I J
84A B C D E F G H I J
85A B C D E F G H I J
86A B C D E F G H I J
87A B C D E F G H I J
88A B C D E F G H I J
89A B C D E F G H I J
90A B C D E F G H I J
91A B C D E F G H I J
92A B C D E F G H I J
93A B C D E F G H I J
94A B C D E F G H I J
95A B C D E F G H I J
96A B C D E F G H I J
97A B C D E F G H I J
98A B C D E F G H I J
99A B C D E F G H I J
100A B C D E F G H I J
101A B C D E F G H I J
102A B C D E F G H I J
103A B C D E F G H I J
104A B C D E F G H I J
105A B C D E F G H I J
106A B C D E F G H I J
107A B C D E F G H I J
108A B C D E F G H I J
109A B C D E F G H I J
110A B C D E F G H I J
111A B C D E F G H I J
112A B C D E F G H I J
113A B C D E F G H I J
114A B C D E F G H I J
115A B C D E F G H I J
116A B C D E F G H I J
117A B C D E F G H I J
118A B C D E F G H I J
119A B C D E F G H I J
120A B C D E F G H I J
121A B C D E F G H I J
122A B C D E F G H I J
123A B C D E F G H I J
124A B C D E F G H I J
125A B C D E F G H I J
126A B C D E F G H I J
127A B C D E F G H I J
128A B C D E F G H I J
129A B C D E F G H I J
130A B C D E F G H I J
131A B C D E F G H I J
132A B C D E F G H I J
133A B C D E F G H I J
134A B C D E F G H I J
135A B C D E F G H I J
136A B C D E F G H I J
137A B C D E F G H I J
138A B C D E F G H I J
139A B C D E F G H I J
140A B C D E F G H I J
141A B C D E F G H I J
142A B C D E F G H I J
143A B C D E F G H I J
144A B C D E F G H I J
145A B C D E F G H I J
146A B C D E F G H I J
147A B C D E F G H I J
148A B C D E F G H I J
149A B C D E F G H I J
150A B C D E F G H I J
151A B C D E F G H I J
152A B C D E F G H I J
153A B C D E F G H I J
154A B C D E F G H I J
155A B C D E F G H I J
156A B C D E F G H I J
157A B C D E F G H I J
158A B C D E F G H I J
159A B C D E F G H I J
160A B C D E F G H I J
161A B C D E F G H I J
162A B C D E F G H I J
163A B C D E F G H I J
164A B C D E F G H I J
165A B C D E F G H I J
166A B C D E F G H I J
167A B C D E F G H I J
168A B C D E F G H I J
169A B C D E F G H I J
170A B C D E F G H I J
171A B C D E F G H I J
172A B C D E F G H I J
173A B C D E F G H I J
174A B C D E F G H I J
175A B C D E F G H I J
176A B C D E F G H I J
177A B C D E F G H I J
178A B C D E F G H I J
179A B C D E F G H I J
180A B C D E F G H I J
181A B C D E F G H I J
182A B C D E F G H I J
183A B C D E F G H I J
184A B C D E F G H I J
185A B C D E F G H I J
186A B C D E F G H I J
187A B C D E F G H I J
188A B C D E F G H I J
189A B C D E F G H I J
190A B C D E F G H I J
191A B C D E F G H I J
192A B C D E F G H I J
193A B C D E F G H I J
194A B C D E F G H I J
195A B C D E F G H I J
196A B C D E F G H I J
197A B C D E F G H I J
198A B C D E F G H I J
199A B C D E F G H I J
200A B C D E F G H I J
201A B C D E F G H I J
202A B C D E F G H I J
203A B C D E F G H I J
204A B C D E F G H I J
205A B C D E F G H I J
206A B C D E F G H I J
207A B C D E F G H I J
208A B C D E F G H I J
209A B C D E F G H I J
210A B C D E F G H I J
211A B C D E F G H I J
212A B C D E F G H I J
213A B C D E F G H I J
214A B C D E F G H I J
215A B C D E F G H I J
216A B C D E F G H I J
217A B C D E F G H I J
218A B C D E F G H I J
219A B C D E F G H I J
220A B C D E F G H I J
221A B C D E F G H I J
222A B C D E F G H I J
223A B C D E F G H I J
224A B C D E F G H I J
225A B C D E F G H I J
226A B C D E F G H I J
227A B C D E F G H I J
228A B C D E F G H I J
229A B C D E F G H I J
230A B C D E F G H I J
231A B C D E F G H I J
232A B C D E F G H I J
233A B C D E F G H I J
234A B C D E F G H I J
235A B C D E F G H I J
236A B C D E F G H I J
237A B C D E F G H I J
238A B C D E F G H I J
239A B C D E F G H I J
240A B C D E F G H I J
241A B C D E F G H I J
242A B C D E F G H I J
243A B C D E F G H I J
244A B C D E F G H I J
245A B C D E F G H I J
246A B C D E F G H I J
247A B C D E F G H I J
248A B C D E F G H I J
249A B C D E F G H I J
250A B C D E F G H I J
251A B C D E F G H I J
252A B C D E F G H I J
253A B C D E F G H I J
254A B C D E F G H I J
255A B C D E F G H I J
256A B C D E F G H I J
257A B C D E F G H I J
258A B C D E F G H I J
259A B C D E F G H I J
260A B C D E F G H I J
261A B C D E F G H I J
262A B C D E F G H I J
263A B C D E F G H I J
264A B C D E F G H I J
265A B C D E F G H I J
266A B C D E F G H I J
267A B C D E F G H I J
268A B C D E F G H I J
269A B C D E F G H I J
270A B C D E F G H I J
271A B C D E F G H I J
272A B C D E F G H I J
273A B C D E F G H I J
274A B C D E F G H I J
275A B C D E F G H I J
276A B C D E F G H I J
277A B C D E F G H I J
278A B C D E F G H I J
279A B C D E F G H I J
280A B C D E F G H I J
281A B C D E F G H I J
282A B C D E F G H I J
283A B C D E F G H I J
284A B C D E F G H I J
285A B C D E F G H I J
286A B C D E F G H I J
287A B C D E F G H I J
288A B C D E F G H I J
289A B C D E F G H I J
290A B C D E F G H I J
291A B C D E F G H I J
292A B C D E F G H I J
293A B C D E F G H I J
294A B C D E F G H I J
295A B C D E F G H I J
296A B C D E F G H I J
297A B C D E F G H I J
298A B C D E F G H I J
299A B C D E F G H I J
300A B C D E F G H I J
301A B C D E F G H I J
302A B C D E F G H I J
303A B C D E F G H I J
304A B C D E F G H I J
305A B C D E F G H I J
306A B C D E F G H I J
307A B C D E F G H I J
308A B C D E F G H I J
309A B C D E F G H I J
310A B C D E F G H I J
311A B C D E F G H I J
312A B C D E F G H I J
313A B C D E F G H I J
314A B C D E F G H I J
315A B C D E F G H I J
316A B C D E F G H I J
317A B C D E F G H I J
318A B C D E F G H I J
319A B C D E F G H I J
320A B C D E F G H I J
321A B C D E F G H I J
322A B C D E F G H I J
323A B C D E F G H I J
324A B C D E F G H I J
325A B C D E F G H I J
326A B C D E F G H I J
327A B C D E F G H I J
328A B C D E F G H I J
329A B C D E F G H I J
330A B C D E F G H I J
331A B C D E F G H I J
332A B C D E F G H I J
333A B C D E F G H I J
334A B C D E F G H I J
335A B C D E F G H I J
336A B C D E F G H I J
337A B C D E F G H I J
338A B C D E F G H I J
339A B C D E F G H I J
340A B C D E F G H I J
341A B C D E F G H I J
342A B C D E F G H I J
343A B C D E F G H I J
344A B C D E F G H I J
345A B C D E F G H I J
346A B C D E F G H I J
347A B C D E F G H I J
348A B C D E F G H I J
349A B C D E F G H I J
350A B C D E F G H I J
351A B C D E F G H I J
352A B C D E F G H I J
353A B C D E F G H I J
354A B C D E F G H I J
355A B C D E F G H I J
356A B C D E F G H I J
357A B C D E F G H I J
358A B C D E F G H I J
359A B C D E F G H I J
360A B C D E F G H I J
361A B C D E F G H I J
362A B C D E F G H I J
363A B C D E F G H I J
364A B C D E F G H I J
365A B C D E F G H I J
366A B C D E F G H I J
367A B C D E F G H I J
368A B C D E F G H I J
369A B C D E F G H I J
370A B C D E F G H I J
371A B C D E F G H I J
372A B C D E F G H I J
373A B C D E F G H I J
374A B C D E F G H I J
375A B C D E F G H I J
376Done
377