1--TEST--
2PL/SQL oci_bind_by_name with SQLT_AFC aka CHAR to VARCHAR2 parameter
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.
8preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
9if (!(isset($matches[0]) && $matches[1] < 12)) {
10    die("skip expected output only valid when using pre-Oracle 12c database");
11}
12?>
13--ENV--
14NLS_LANG=.AL32UTF8
15--FILE--
16<?php
17
18// Same test as bind_char_3 but the PL/SQL function uses VARCHAR2 instead of CHAR
19
20require(dirname(__FILE__).'/connect.inc');
21
22// Initialization
23
24$stmtarray = array(
25	"create or replace function bind_char_3_fn(p1 varchar2) return varchar2 as begin return p1; end;",
26);
27
28oci8_test_sql_execute($c, $stmtarray);
29
30// Run Test
31
32echo "Test 1.1 In Length: default.  In Type: default.  Out Length: default.          Out Type: default\n";
33
34$s = oci_parse($c, "begin :bv2 := bind_char_3_fn(:bv1); end;");
35$bv1 = 'abc';
36$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2);
37if ($r)
38	do_e($s);
39var_dump($bv1, $bv2);
40
41echo "Test 1.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default\n";
42
43$bv1 = 'abc';
44$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2, 10);
45if ($r)
46	do_e($s);
47var_dump($bv1, $bv2);
48
49
50echo "Test 1.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default\n";
51
52$bv1 = 'abc';
53$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10);
54if ($r)
55	do_e($s);
56var_dump($bv1, $bv2);
57
58
59
60echo "Test 1.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC\n";
61
62$bv1 = 'abc';
63$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC);
64if ($r)
65	do_e($s);
66var_dump($bv1, $bv2);
67
68
69echo "Test 1.5 In Length: strlen.   In Type: AFC.      Out Length: strlen(input).    Out Type: AFC\n";
70
71$bv1 = 'abc';
72$r = oci_bind_by_name($s, ':bv1', $bv1, strlen($bv1), SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, strlen($bv1), SQLT_AFC);
73if ($r)
74	do_e($s);
75var_dump($bv1, $bv2);
76
77
78echo "Test 1.6 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)-1.  Out Type: AFC\n";
79
80$bv1 = 'abc';
81$r = oci_bind_by_name($s, ':bv1', $bv1, strlen($bv1), SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, strlen($bv1)-1, SQLT_AFC);
82if ($r)
83	do_e($s);
84var_dump($bv1, $bv2);
85
86
87echo "Test 1.7 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)+1.  Out Type: AFC\n";
88
89$bv1 = 'abc';
90$r = oci_bind_by_name($s, ':bv1', $bv1, strlen($bv1), SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, strlen($bv1)+1, SQLT_AFC);
91if ($r)
92	do_e($s);
93var_dump($bv1, $bv2);
94
95
96echo "\n\nTests with ''\n\n";
97
98echo "Test 2.1 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC\n";
99
100$bv1 = '';
101$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC);
102if ($r)
103	do_e($s);
104var_dump($bv1, $bv2);
105
106
107echo "Test 2.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default\n";
108
109$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2, 10);
110if ($r)
111	do_e($s);
112var_dump($bv1, $bv2);
113
114
115
116echo "Test 2.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default\n";
117
118$bv1 = '';
119$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10);
120if ($r)
121	do_e($s);
122var_dump($bv1, $bv2);
123
124
125
126echo "Test 2.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC\n";
127
128$bv1 = '';
129$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC);
130if ($r)
131	do_e($s);
132var_dump($bv1, $bv2);
133
134
135
136echo "Test 2.5 In Length: -1.       In Type: AFC.      Out Length: 0.                Out Type: AFC\n";
137
138$bv1 = '';
139$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 0, SQLT_AFC);
140if ($r)
141	do_e($s);
142var_dump($bv1, $bv2);
143
144
145
146echo "Test 2.6 In Length: 0.        In Type: AFC.      Out Length: 0.                Out Type: AFC\n";
147
148$bv1 = '';
149$r = oci_bind_by_name($s, ':bv1', $bv1, 0, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 0, SQLT_AFC);
150if ($r)
151	do_e($s);
152var_dump($bv1, $bv2);
153
154
155
156echo "Test 2.7 In Length: 1.        In Type: AFC.      Out Length: 1.                Out Type: AFC\n";
157
158$bv1 = '';
159$r = oci_bind_by_name($s, ':bv1', $bv1, 1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 1, SQLT_AFC);
160if ($r)
161	do_e($s);
162var_dump($bv1, $bv2);
163
164
165
166echo "\n\nTests with NULL\n";
167
168echo "Test 3.1 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC\n";
169
170$bv1 = null;
171$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC);
172if ($r)
173	do_e($s);
174var_dump($bv1, $bv2);
175
176
177echo "Test 3.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default\n";
178
179$bv1 = null;
180$r = oci_bind_by_name($s, ':bv1', $bv1) && oci_bind_by_name($s, ':bv2', $bv2, 10);
181if ($r)
182	do_e($s);
183var_dump($bv1, $bv2);
184
185
186
187echo "Test 3.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default\n";
188
189$bv1 = null;
190$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10);
191if ($r)
192	do_e($s);
193var_dump($bv1, $bv2);
194
195
196
197echo "Test 3.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC\n";
198
199$bv1 = null;
200$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 10, SQLT_AFC);
201if ($r)
202	do_e($s);
203var_dump($bv1, $bv2);
204
205
206echo "Test 3.5 In Length: -1.       In Type: AFC.      Out Length: 0.                Out Type: AFC\n";
207
208$bv1 = null;
209$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 0, SQLT_AFC);
210if ($r)
211	do_e($s);
212var_dump($bv1, $bv2);
213
214
215
216echo "Test 3.6 In Length: -1.       In Type: AFC.      Out Length: 1.                Out Type: AFC\n";
217
218$bv1 = null;
219$r = oci_bind_by_name($s, ':bv1', $bv1, -1, SQLT_AFC) && oci_bind_by_name($s, ':bv2', $bv2, 1, SQLT_AFC);
220if ($r)
221	do_e($s);
222var_dump($bv1, $bv2);
223
224
225function do_e($s)
226{
227	echo "  Executing:\n";
228
229	$r = @oci_execute($s);
230	if (!$r) {
231		$m = oci_error($s);
232		echo "    Oci_execute error ORA-".$m['code']."\n";
233		return;
234	}
235}
236
237// Cleanup
238
239$stmtarray = array(
240	"drop function bind_char_3_fn"
241);
242
243oci8_test_sql_execute($c, $stmtarray);
244
245echo "Done\n";
246
247?>
248--EXPECT--
249Test 1.1 In Length: default.  In Type: default.  Out Length: default.          Out Type: default
250  Executing:
251    Oci_execute error ORA-6502
252string(3) "abc"
253NULL
254Test 1.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default
255  Executing:
256string(3) "abc"
257string(3) "abc"
258Test 1.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default
259  Executing:
260string(3) "abc"
261string(3) "abc"
262Test 1.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC
263  Executing:
264string(3) "abc"
265string(10) "abc       "
266Test 1.5 In Length: strlen.   In Type: AFC.      Out Length: strlen(input).    Out Type: AFC
267  Executing:
268string(3) "abc"
269string(3) "abc"
270Test 1.6 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)-1.  Out Type: AFC
271  Executing:
272    Oci_execute error ORA-6502
273string(3) "abc"
274string(3) "abc"
275Test 1.7 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)+1.  Out Type: AFC
276  Executing:
277string(3) "abc"
278string(4) "abc "
279
280
281Tests with ''
282
283Test 2.1 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC
284  Executing:
285string(0) ""
286NULL
287Test 2.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default
288  Executing:
289string(0) ""
290NULL
291Test 2.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default
292  Executing:
293string(0) ""
294NULL
295Test 2.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC
296  Executing:
297string(0) ""
298NULL
299Test 2.5 In Length: -1.       In Type: AFC.      Out Length: 0.                Out Type: AFC
300  Executing:
301string(0) ""
302NULL
303Test 2.6 In Length: 0.        In Type: AFC.      Out Length: 0.                Out Type: AFC
304  Executing:
305string(0) ""
306NULL
307Test 2.7 In Length: 1.        In Type: AFC.      Out Length: 1.                Out Type: AFC
308  Executing:
309string(0) ""
310NULL
311
312
313Tests with NULL
314Test 3.1 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC
315  Executing:
316NULL
317NULL
318Test 3.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default
319  Executing:
320NULL
321NULL
322Test 3.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default
323  Executing:
324NULL
325NULL
326Test 3.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC
327  Executing:
328NULL
329NULL
330Test 3.5 In Length: -1.       In Type: AFC.      Out Length: 0.                Out Type: AFC
331  Executing:
332NULL
333NULL
334Test 3.6 In Length: -1.       In Type: AFC.      Out Length: 1.                Out Type: AFC
335  Executing:
336NULL
337NULL
338Done
339