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