Annotation of embedaddon/php/ext/oci8/tests/bug42841.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Bug #42841 (REF CURSOR and oci_new_cursor PHP crash)
3: --SKIPIF--
4: <?php
5: $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
6: require(dirname(__FILE__).'/skipif.inc');
7: ?>
8: --INI--
9: oci8.statement_cache_size=20
10: --FILE--
11: <?php
12:
13: require dirname(__FILE__).'/details.inc';
14:
15: // note a oci_new_connect() occurs lower in the script
16: $c = oci_connect($user, $password, $dbase);
17:
18: // Initialization
19:
20: $stmtarray = array(
21: "create or replace procedure bug42841_proc(out_1 out sys_refcursor) is
22: begin
23: open out_1 for select 11 from dual union all select 12 from dual union all select 13 from dual;
24: end bug42841_proc;",
25:
26: "create or replace package bug43449_pkg is
27: type cursortype is ref Cursor;
28: function testcursor return cursortype;
29: end bug43449_pkg;",
30:
31: "create or replace package body bug43449_pkg is
32: function testcursor return cursortype is
33: retCursor cursorType;
34: begin
35: Open retCursor For 'select * from dual';
36: return retCursor;
37: end;
38: end bug43449_pkg;"
39: );
40:
41: oci8_test_sql_execute($c, $stmtarray);
42:
43: // Main code
44:
45: function do_bug42841($c)
46: {
47: echo "First attempt\n";
48:
49: $sql = "BEGIN bug42841_proc(:cursor); END;";
50: $stmt = oci_parse($c, $sql);
51: $cursor = oci_new_cursor($c);
52: oci_bind_by_name($stmt, ":cursor", $cursor, -1, OCI_B_CURSOR);
53:
54: oci_execute($stmt, OCI_DEFAULT);
55: oci_execute($cursor);
56:
57: while($row = oci_fetch_array($cursor, OCI_ASSOC + OCI_RETURN_LOBS)) {
58: $data1[] = $row;
59: }
60:
61: oci_free_statement($stmt);
62: oci_free_statement($cursor);
63: var_dump($data1);
64:
65: echo "Second attempt\n";
66:
67: $sql = "BEGIN bug42841_proc(:cursor); END;";
68: $stmt = oci_parse($c, $sql);
69: $cursor = oci_new_cursor($c);
70: oci_bind_by_name($stmt, ":cursor", $cursor, -1, OCI_B_CURSOR);
71:
72: oci_execute($stmt, OCI_DEFAULT);
73: oci_execute($cursor);
74:
75: while($row = oci_fetch_array($cursor, OCI_ASSOC + OCI_RETURN_LOBS)) {
76: $data2[] = $row;
77: }
78:
79: oci_free_statement($stmt);
80: oci_free_statement($cursor);
81: var_dump($data2);
82: }
83:
84: function do_bug43449($c)
85: {
86:
87: for ($i = 0; $i < 2; $i++) {
88: var_dump(bug43449_getCur($c));
89: }
90: }
91:
92: function bug43449_getCur($c)
93: {
94: $cur = oci_new_cursor($c);
95: $stmt = oci_parse($c, 'begin :cur := bug43449_pkg.testcursor; end;');
96: oci_bind_by_name($stmt, ':cur', $cur, -1, OCI_B_CURSOR);
97: oci_execute($stmt, OCI_DEFAULT);
98: oci_execute($cur, OCI_DEFAULT);
99:
100: $ret = array();
101:
102: while (ocifetchinto($cur, $row, OCI_ASSOC)) {
103: $ret[] = $row;
104: }
105:
106: oci_free_statement($cur);
107: oci_free_statement($stmt);
108: return $ret;
109: }
110:
111: echo "Test bug 42841: Procedure with OUT cursor parameter\n";
112: do_bug42841($c);
113:
114: $c = oci_new_connect($user, $password, $dbase);
115:
116: echo "Test bug 43449: Cursor as function result\n";
117: do_bug43449($c);
118:
119: // Cleanup
120:
121: $stmtarray = array(
122: "drop procedure bug42841_proc",
123: "drop package bug43449_pkg"
124: );
125:
126: oci8_test_sql_execute($c, $stmtarray);
127:
128: echo "Done\n";
129:
130: ?>
131: --EXPECT--
132: Test bug 42841: Procedure with OUT cursor parameter
133: First attempt
134: array(3) {
135: [0]=>
136: array(1) {
137: [11]=>
138: string(2) "11"
139: }
140: [1]=>
141: array(1) {
142: [11]=>
143: string(2) "12"
144: }
145: [2]=>
146: array(1) {
147: [11]=>
148: string(2) "13"
149: }
150: }
151: Second attempt
152: array(3) {
153: [0]=>
154: array(1) {
155: [11]=>
156: string(2) "11"
157: }
158: [1]=>
159: array(1) {
160: [11]=>
161: string(2) "12"
162: }
163: [2]=>
164: array(1) {
165: [11]=>
166: string(2) "13"
167: }
168: }
169: Test bug 43449: Cursor as function result
170: array(1) {
171: [0]=>
172: array(1) {
173: ["DUMMY"]=>
174: string(1) "X"
175: }
176: }
177: array(1) {
178: [0]=>
179: array(1) {
180: ["DUMMY"]=>
181: string(1) "X"
182: }
183: }
184: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>