1--TEST--
2SELECT oci_bind_by_name with SQLT_AFC aka CHAR
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require(__DIR__."/connect.inc");
8// The bind buffer size edge cases seem to change each DB version.
9preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
10if (!(isset($matches[0]) && $matches[1] < 12)) {
11    die("skip expected output only valid when using pre-Oracle 12c database");
12}
13?>
14--ENV--
15NLS_LANG=.AL32UTF8
16--FILE--
17<?php
18
19// Output is for 32 bit client to 64bit 11.1.0.6
20
21require(__DIR__.'/connect.inc');
22
23// Initialization
24
25$stmtarray = array(
26    "drop table bind_char_tab",
27    "create table bind_char_tab (id number, c1 char(10), c2 varchar2(10))",
28    "insert into bind_char_tab values (1, 'abc', NULL)",
29    "insert into bind_char_tab values (2, NULL, 'abc')",
30    "insert into bind_char_tab values (3, NULL, 'abc       ')"
31);
32
33oci8_test_sql_execute($c, $stmtarray);
34
35// Run Test
36
37echo "*** Non-null Data Tests against CHAR***\n";
38
39$bv1 = 'abc';
40
41echo "Test 1.1: Type: default.  Length: default\n";
42$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv");
43$r = oci_bind_by_name($s, ":bv", $bv1);
44if ($r)
45    do_e_q($s);
46
47echo "Test 1.2: Type: AFC.  Length: default\n";
48$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
49if ($r)
50    do_e_q($s);
51
52echo "Test 1.3: Type: AFC:  Length: 0\n";
53$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
54if ($r)
55    do_e_q($s);
56
57echo "Test 1.4: Type: AFC:  Length: strlen\n";
58$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
59if ($r)
60    do_e_q($s);
61
62echo "Test 1.5: Type: AFC.  Length: strlen-1\n";
63$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
64if ($r)
65    do_e_q($s);
66
67echo "Test 1.6: Type: AFC.  Length: strlen+1\n";
68$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
69if ($r)
70    do_e_q($s);
71
72echo "\n\n*** NULL data tests against CHAR ***\n";
73
74$bv1 = null;
75
76echo "Test 2.1: Type: default.  Length: default\n";
77$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv");
78$r = oci_bind_by_name($s, ":bv", $bv1);
79if ($r)
80    do_e_q($s);
81
82echo "Test 2.2: Type: AFC.  Length: default\n";
83$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
84if ($r)
85    do_e_q($s);
86
87echo "Test 2.3: Type: AFC:  Length: 0\n";
88$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
89if ($r)
90    do_e_q($s);
91
92echo "Test 2.4: Type: AFC:  Length: strlen\n";
93$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
94if ($r)
95    do_e_q($s);
96
97echo "Test 2.5: Type: AFC.  Length: strlen-1\n";
98$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
99if ($r)
100    do_e_q($s);
101
102echo "Test 2.6: Type: AFC.  Length: strlen+1\n";
103$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
104if ($r)
105    do_e_q($s);
106
107
108echo "\n\n*** Non-null Data Tests against VARCHAR2***\n";
109
110$bv1 = 'abc';
111
112echo "Test 3.1: Type: default.  Length: default\n";
113$s = oci_parse($c, "select * from bind_char_tab where c2 = :bv");
114$r = oci_bind_by_name($s, ":bv", $bv1);
115if ($r)
116    do_e_q($s);
117
118echo "Test 3.2: Type: AFC.  Length: default\n";
119$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
120if ($r)
121    do_e_q($s);
122
123echo "Test 3.3: Type: AFC:  Length: 0\n";
124$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
125if ($r)
126    do_e_q($s);
127
128echo "Test 3.4: Type: AFC:  Length: strlen\n";
129$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
130if ($r)
131    do_e_q($s);
132
133echo "Test 3.5: Type: AFC.  Length: strlen-1\n";
134$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
135if ($r)
136    do_e_q($s);
137
138echo "Test 3.6: Type: AFC.  Length: strlen+1\n";
139$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
140if ($r)
141    do_e_q($s);
142
143
144echo "\n\n*** NULL data tests against VARCHAR2 ***\n";
145
146$bv1 = null;
147
148echo "Test 4.1: Type: default.  Length: default\n";
149$s = oci_parse($c, "select * from bind_char_tab where c2 = :bv");
150$r = oci_bind_by_name($s, ":bv", $bv1);
151if ($r)
152    do_e_q($s);
153
154echo "Test 4.2: Type: AFC.  Length: default\n";
155$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
156if ($r)
157    do_e_q($s);
158
159echo "Test 4.3: Type: AFC:  Length: 0\n";
160$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
161if ($r)
162    do_e_q($s);
163
164echo "Test 4.4: Type: AFC:  Length: strlen\n";
165$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
166if ($r)
167    do_e_q($s);
168
169echo "Test 4.5: Type: AFC.  Length: strlen-1\n";
170$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
171if ($r)
172    do_e_q($s);
173
174echo "Test 4.6: Type: AFC.  Length: strlen+1\n";
175$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
176if ($r)
177    do_e_q($s);
178
179
180
181function do_e_q($s)
182{
183    echo "  Querying:\n";
184
185    $r = @oci_execute($s);
186    if (!$r) {
187        $m = oci_error($s);
188        echo "    Oci_execute error ORA-".$m['code']." Exiting Query\n";
189        return;
190    }
191    while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) {
192        foreach ($row as $item) {
193            echo "    :" . $item . ":\n";
194        }
195    }
196}
197
198// Cleanup
199$stmtarray = array(
200    "drop table bind_char_tab"
201);
202
203oci8_test_sql_execute($c, $stmtarray);
204
205echo "Done\n";
206
207?>
208--EXPECT--
209*** Non-null Data Tests against CHAR***
210Test 1.1: Type: default.  Length: default
211  Querying:
212Test 1.2: Type: AFC.  Length: default
213  Querying:
214    :1:
215    :abc       :
216    ::
217Test 1.3: Type: AFC:  Length: 0
218  Querying:
219    :1:
220    :abc       :
221    ::
222Test 1.4: Type: AFC:  Length: strlen
223  Querying:
224    :1:
225    :abc       :
226    ::
227Test 1.5: Type: AFC.  Length: strlen-1
228  Querying:
229Test 1.6: Type: AFC.  Length: strlen+1
230  Querying:
231    :1:
232    :abc       :
233    ::
234
235
236*** NULL data tests against CHAR ***
237Test 2.1: Type: default.  Length: default
238  Querying:
239Test 2.2: Type: AFC.  Length: default
240  Querying:
241Test 2.3: Type: AFC:  Length: 0
242  Querying:
243Test 2.4: Type: AFC:  Length: strlen
244  Querying:
245Test 2.5: Type: AFC.  Length: strlen-1
246  Querying:
247Test 2.6: Type: AFC.  Length: strlen+1
248  Querying:
249
250
251*** Non-null Data Tests against VARCHAR2***
252Test 3.1: Type: default.  Length: default
253  Querying:
254    :2:
255    ::
256    :abc:
257Test 3.2: Type: AFC.  Length: default
258  Querying:
259    :2:
260    ::
261    :abc:
262Test 3.3: Type: AFC:  Length: 0
263  Querying:
264    :2:
265    ::
266    :abc:
267Test 3.4: Type: AFC:  Length: strlen
268  Querying:
269    :2:
270    ::
271    :abc:
272Test 3.5: Type: AFC.  Length: strlen-1
273  Querying:
274Test 3.6: Type: AFC.  Length: strlen+1
275  Querying:
276    :2:
277    ::
278    :abc:
279
280
281*** NULL data tests against VARCHAR2 ***
282Test 4.1: Type: default.  Length: default
283  Querying:
284Test 4.2: Type: AFC.  Length: default
285  Querying:
286Test 4.3: Type: AFC:  Length: 0
287  Querying:
288Test 4.4: Type: AFC:  Length: strlen
289  Querying:
290Test 4.5: Type: AFC.  Length: strlen-1
291  Querying:
292Test 4.6: Type: AFC.  Length: strlen+1
293  Querying:
294Done
295