xref: /PHP-5.6/ext/oci8/tests/bind_char_4.phpt (revision 0d909f5b)
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 Oracle 12c database");
11}
12?>
13--ENV--
14NLS_LANG=
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--EXPECTF--
249Test 1.1 In Length: default.  In Type: default.  Out Length: default.          Out Type: default
250  Executing:
251string(3) "abc"
252string(3) "abc"
253Test 1.2 In Length: default.  In Type: default.  Out Length: 10.               Out Type: default
254  Executing:
255string(3) "abc"
256string(3) "abc"
257Test 1.3 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: default
258  Executing:
259string(3) "abc"
260string(3) "abc"
261Test 1.4 In Length: -1.       In Type: AFC.      Out Length: 10.               Out Type: AFC
262  Executing:
263string(3) "abc"
264string(30) "abc                           "
265Test 1.5 In Length: strlen.   In Type: AFC.      Out Length: strlen(input).    Out Type: AFC
266  Executing:
267string(3) "abc"
268string(9) "abc      "
269Test 1.6 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)-1.  Out Type: AFC
270  Executing:
271string(3) "abc"
272string(6) "abc   "
273Test 1.7 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)+1.  Out Type: AFC
274  Executing:
275string(3) "abc"
276string(12) "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