1--TEST--
2SELECT oci_bind_by_name with SQLT_AFC aka CHAR
3--SKIPIF--
4<?php
5if (!extension_loaded('oci8')) die ("skip no oci8 extension");
6require(dirname(__FILE__)."/connect.inc");
7// The bind buffer size edge cases seem to change each DB version.
8if (preg_match('/Release 11\.1\./', oci_server_version($c), $matches) !== 1) {
9    if (preg_match('/Release 11\.2\.0\.3/', oci_server_version($c), $matches) !== 1) {
10        die("skip expected output only valid when using Oracle 11gR1 or 11.2.0.3 databases");
11    }
12}
13?>
14--ENV--
15NLS_LANG=
16--FILE--
17<?php
18
19// Output is for 32 bit client to 64bit 11.1.0.6
20
21require(dirname(__FILE__).'/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    Oci_execute error ORA-1460 Exiting Query
220Test 1.4: Type: AFC:  Length: strlen
221  Querying:
222    :1:
223    :abc       :
224    ::
225Test 1.5: Type: AFC.  Length: strlen-1
226  Querying:
227    Oci_execute error ORA-1460 Exiting Query
228Test 1.6: Type: AFC.  Length: strlen+1
229  Querying:
230    :1:
231    :abc       :
232    ::
233
234
235*** NULL data tests against CHAR ***
236Test 2.1: Type: default.  Length: default
237  Querying:
238Test 2.2: Type: AFC.  Length: default
239  Querying:
240Test 2.3: Type: AFC:  Length: 0
241  Querying:
242Test 2.4: Type: AFC:  Length: strlen
243  Querying:
244Test 2.5: Type: AFC.  Length: strlen-1
245  Querying:
246Test 2.6: Type: AFC.  Length: strlen+1
247  Querying:
248
249
250*** Non-null Data Tests against VARCHAR2***
251Test 3.1: Type: default.  Length: default
252  Querying:
253    :2:
254    ::
255    :abc:
256Test 3.2: Type: AFC.  Length: default
257  Querying:
258    :2:
259    ::
260    :abc:
261Test 3.3: Type: AFC:  Length: 0
262  Querying:
263    Oci_execute error ORA-1460 Exiting Query
264Test 3.4: Type: AFC:  Length: strlen
265  Querying:
266    :2:
267    ::
268    :abc:
269Test 3.5: Type: AFC.  Length: strlen-1
270  Querying:
271    Oci_execute error ORA-1460 Exiting Query
272Test 3.6: Type: AFC.  Length: strlen+1
273  Querying:
274    :2:
275    ::
276    :abc:
277
278
279*** NULL data tests against VARCHAR2 ***
280Test 4.1: Type: default.  Length: default
281  Querying:
282Test 4.2: Type: AFC.  Length: default
283  Querying:
284Test 4.3: Type: AFC:  Length: 0
285  Querying:
286Test 4.4: Type: AFC:  Length: strlen
287  Querying:
288Test 4.5: Type: AFC.  Length: strlen-1
289  Querying:
290Test 4.6: Type: AFC.  Length: strlen+1
291  Querying:
292Done
293