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