xref: /PHP-8.2/ext/oci8/tests/bug51253.phpt (revision b5a14e6c)
1--TEST--
2Bug #51253 (oci_bind_array_by_name() array references)
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$drop = "DROP table bind_test";
16$statement = oci_parse($c, $drop);
17@oci_execute($statement);
18
19$create = "CREATE table bind_test(name VARCHAR(20))";
20$statement = oci_parse($c, $create);
21oci_execute($statement);
22
23$create_pkg = "
24CREATE OR REPLACE PACKAGE BUG51253_PKG AS
25  TYPE ARRTYPE IS TABLE OF VARCHAR(20) INDEX BY BINARY_INTEGER;
26  PROCEDURE iobind(c1 IN OUT ARRTYPE);
27END BUG51253_PKG;";
28$statement = oci_parse($c, $create_pkg);
29oci_execute($statement);
30
31$create_pkg_body = "
32CREATE OR REPLACE PACKAGE BODY BUG51253_PKG AS
33  CURSOR CUR IS SELECT name FROM bind_test;
34  PROCEDURE iobind(c1 IN OUT ARRTYPE) IS
35    BEGIN
36    FOR i IN 1..5 LOOP
37      INSERT INTO bind_test VALUES (c1(i));
38    END LOOP;
39    IF NOT CUR%ISOPEN THEN
40      OPEN CUR;
41    END IF;
42    FOR i IN REVERSE 1..5 LOOP
43      FETCH CUR INTO c1(i);
44      IF CUR%NOTFOUND THEN
45        CLOSE CUR;
46        EXIT;
47      END IF;
48    END LOOP;
49  END iobind;
50END BUG51253_PKG;";
51$statement = oci_parse($c, $create_pkg_body);
52oci_execute($statement);
53
54echo "Test 1\n";
55$statement = oci_parse($c, "BEGIN bug51253_pkg.iobind(:c1); END;");
56$array1 = array("one", "two", "three", "four", "five");
57$array2 = $array1;
58oci_bind_array_by_name($statement, ":c1", $array2, 5, -1, SQLT_CHR);
59oci_execute($statement);
60
61var_dump($array1);
62var_dump($array2);
63
64
65echo "Test 2\n";
66$statement = oci_parse($c, "BEGIN bug51253_pkg.iobind(:c1); END;");
67$array1 = array("one", "two", "three", "four", "five");
68$array2 = &$array1;
69oci_bind_array_by_name($statement, ":c1", $array2, 5, -1, SQLT_CHR);
70oci_execute($statement);
71
72var_dump($array1);
73var_dump($array2);
74
75
76echo "Test 3\n";
77$statement = oci_parse($c, "BEGIN bug51253_pkg.iobind(:c1); END;");
78$array1 = array("one", "two", "three", "four", "five");
79$array2 = &$array1;
80oci_bind_array_by_name($statement, ":c1", $array1, 5, -1, SQLT_CHR);
81oci_execute($statement);
82
83var_dump($array1);
84var_dump($array2);
85
86// Cleanup
87$statement = oci_parse($c, "DROP PACKAGE BUG51253_PKG");
88@oci_execute($statement);
89$statement = oci_parse($c, "DROP TABLE BIND_TEST");
90@oci_execute($statement);
91
92echo "Done\n";
93?>
94--EXPECT--
95Test 1
96array(5) {
97  [0]=>
98  string(3) "one"
99  [1]=>
100  string(3) "two"
101  [2]=>
102  string(5) "three"
103  [3]=>
104  string(4) "four"
105  [4]=>
106  string(4) "five"
107}
108array(5) {
109  [0]=>
110  string(4) "five"
111  [1]=>
112  string(4) "four"
113  [2]=>
114  string(5) "three"
115  [3]=>
116  string(3) "two"
117  [4]=>
118  string(3) "one"
119}
120Test 2
121array(5) {
122  [0]=>
123  string(3) "one"
124  [1]=>
125  string(3) "two"
126  [2]=>
127  string(5) "three"
128  [3]=>
129  string(4) "four"
130  [4]=>
131  string(4) "five"
132}
133array(5) {
134  [0]=>
135  string(3) "one"
136  [1]=>
137  string(3) "two"
138  [2]=>
139  string(5) "three"
140  [3]=>
141  string(4) "four"
142  [4]=>
143  string(4) "five"
144}
145Test 3
146array(5) {
147  [0]=>
148  string(4) "five"
149  [1]=>
150  string(4) "four"
151  [2]=>
152  string(5) "three"
153  [3]=>
154  string(3) "two"
155  [4]=>
156  string(3) "one"
157}
158array(5) {
159  [0]=>
160  string(4) "five"
161  [1]=>
162  string(4) "four"
163  [2]=>
164  string(5) "three"
165  [3]=>
166  string(3) "two"
167  [4]=>
168  string(3) "one"
169}
170Done
171