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