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