xref: /PHP-5.5/ext/oci8/tests/bind_char_3.phpt (revision 8b4890e1)
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(dirname(__FILE__)."/connect.inc");
7// The bind buffer size edge cases seem to change each DB version.
8if (preg_match('/Release 10\.2\./', oci_server_version($c), $matches) !== 1) {
9    if (preg_match('/Release 11\.2\.0\.2/', oci_server_version($c), $matches) !== 2) {
10        die("skip expected output only valid when using Oracle 10gR2 or 11.2.0.2 databases");
11    }
12}
13if (preg_match('/^11\./', oci_client_version()) != 1) {
14    die("skip test expected to work only with Oracle 11g or greater version of client");
15}
16?>
17--ENV--
18NLS_LANG=
19--FILE--
20<?php
21
22require(dirname(__FILE__).'/connect.inc');
23
24// Initialization
25
26$stmtarray = array(
27	"create or replace function bind_char_3_fn(p1 char) return char 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--EXPECTF--
251Test 1.1 In Length: default.  In Type: default.  Out Length: default.          Out Type: default
252  Executing:
253string(3) "abc"
254string(3) "abc"
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(30) "abc                           "
267Test 1.5 In Length: strlen.   In Type: AFC.      Out Length: strlen(input).    Out Type: AFC
268  Executing:
269string(3) "abc"
270string(9) "abc      "
271Test 1.6 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)-1.  Out Type: AFC
272  Executing:
273string(3) "abc"
274string(6) "abc   "
275Test 1.7 In Length: strlen.   In Type: AFC.      Out Length: strlen(input)+1.  Out Type: AFC
276  Executing:
277string(3) "abc"
278string(12) "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