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