xref: /PHP-5.6/ext/oci8/tests/bind_char_1.phpt (revision 0d909f5b)
1--TEST--
2SELECT oci_bind_by_name with SQLT_AFC aka CHAR
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
18require(dirname(__FILE__).'/connect.inc');
19
20// Initialization
21
22$stmtarray = array(
23	"drop table bind_char_tab",
24	"create table bind_char_tab (id number, c1 char(10), c2 varchar2(10))",
25	"insert into bind_char_tab values (1, 'abc', NULL)",
26	"insert into bind_char_tab values (2, NULL, 'abc')",
27	"insert into bind_char_tab values (3, NULL, 'abc       ')"
28);
29
30oci8_test_sql_execute($c, $stmtarray);
31
32// Run Test
33
34echo "*** Non-null Data Tests against CHAR***\n";
35
36$bv1 = 'abc';
37
38echo "Test 1.1: Type: default.  Length: default\n";
39$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv");
40$r = oci_bind_by_name($s, ":bv", $bv1);
41if ($r)
42	do_e_q($s);
43
44echo "Test 1.2: Type: AFC.  Length: default\n";
45$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
46if ($r)
47	do_e_q($s);
48
49echo "Test 1.3: Type: AFC:  Length: 0\n";
50$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
51if ($r)
52	do_e_q($s);
53
54echo "Test 1.4: Type: AFC:  Length: strlen\n";
55$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
56if ($r)
57	do_e_q($s);
58
59echo "Test 1.5: Type: AFC.  Length: strlen-1\n";
60$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
61if ($r)
62	do_e_q($s);
63
64echo "Test 1.6: Type: AFC.  Length: strlen+1\n";
65$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
66if ($r)
67	do_e_q($s);
68
69echo "\n\n*** NULL data tests against CHAR ***\n";
70
71$bv1 = null;
72
73echo "Test 2.1: Type: default.  Length: default\n";
74$s = oci_parse($c, "select * from bind_char_tab where c1 = :bv");
75$r = oci_bind_by_name($s, ":bv", $bv1);
76if ($r)
77	do_e_q($s);
78
79echo "Test 2.2: Type: AFC.  Length: default\n";
80$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
81if ($r)
82	do_e_q($s);
83
84echo "Test 2.3: Type: AFC:  Length: 0\n";
85$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
86if ($r)
87	do_e_q($s);
88
89echo "Test 2.4: Type: AFC:  Length: strlen\n";
90$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
91if ($r)
92	do_e_q($s);
93
94echo "Test 2.5: Type: AFC.  Length: strlen-1\n";
95$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
96if ($r)
97	do_e_q($s);
98
99echo "Test 2.6: Type: AFC.  Length: strlen+1\n";
100$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
101if ($r)
102	do_e_q($s);
103
104
105echo "\n\n*** Non-null Data Tests against VARCHAR2***\n";
106
107$bv1 = 'abc';
108
109echo "Test 3.1: Type: default.  Length: default\n";
110$s = oci_parse($c, "select * from bind_char_tab where c2 = :bv");
111$r = oci_bind_by_name($s, ":bv", $bv1);
112if ($r)
113	do_e_q($s);
114
115echo "Test 3.2: Type: AFC.  Length: default\n";
116$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
117if ($r)
118	do_e_q($s);
119
120echo "Test 3.3: Type: AFC:  Length: 0\n";
121$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
122if ($r)
123	do_e_q($s);
124
125echo "Test 3.4: Type: AFC:  Length: strlen\n";
126$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
127if ($r)
128	do_e_q($s);
129
130echo "Test 3.5: Type: AFC.  Length: strlen-1\n";
131$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
132if ($r)
133	do_e_q($s);
134
135echo "Test 3.6: Type: AFC.  Length: strlen+1\n";
136$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
137if ($r)
138	do_e_q($s);
139
140
141echo "\n\n*** NULL data tests against VARCHAR2 ***\n";
142
143$bv1 = null;
144
145echo "Test 4.1: Type: default.  Length: default\n";
146$s = oci_parse($c, "select * from bind_char_tab where c2 = :bv");
147$r = oci_bind_by_name($s, ":bv", $bv1);
148if ($r)
149	do_e_q($s);
150
151echo "Test 4.2: Type: AFC.  Length: default\n";
152$r = oci_bind_by_name($s, ":bv", $bv1, -1, SQLT_AFC);
153if ($r)
154	do_e_q($s);
155
156echo "Test 4.3: Type: AFC:  Length: 0\n";
157$r = oci_bind_by_name($s, ":bv", $bv1, 0, SQLT_AFC);
158if ($r)
159	do_e_q($s);
160
161echo "Test 4.4: Type: AFC:  Length: strlen\n";
162$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1), SQLT_AFC);
163if ($r)
164	do_e_q($s);
165
166echo "Test 4.5: Type: AFC.  Length: strlen-1\n";
167$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)-1, SQLT_AFC);
168if ($r)
169	do_e_q($s);
170
171echo "Test 4.6: Type: AFC.  Length: strlen+1\n";
172$r = oci_bind_by_name($s, ":bv", $bv1, strlen($bv1)+1, SQLT_AFC);
173if ($r)
174	do_e_q($s);
175
176
177
178function do_e_q($s)
179{
180	echo "  Querying:\n";
181
182	$r = @oci_execute($s);
183	if (!$r) {
184		$m = oci_error($s);
185		echo "    Oci_execute error ORA-".$m['code']." Exiting Query\n";
186		return;
187	}
188	while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) {
189		foreach ($row as $item) {
190			echo "    :" . $item . ":\n";
191		}
192	}
193}
194
195// Cleanup
196$stmtarray = array(
197	"drop table bind_char_tab"
198);
199
200oci8_test_sql_execute($c, $stmtarray);
201
202echo "Done\n";
203
204?>
205--EXPECT--
206*** Non-null Data Tests against CHAR***
207Test 1.1: Type: default.  Length: default
208  Querying:
209Test 1.2: Type: AFC.  Length: default
210  Querying:
211    :1:
212    :abc       :
213    ::
214Test 1.3: Type: AFC:  Length: 0
215  Querying:
216    :1:
217    :abc       :
218    ::
219Test 1.4: Type: AFC:  Length: strlen
220  Querying:
221    :1:
222    :abc       :
223    ::
224Test 1.5: Type: AFC.  Length: strlen-1
225  Querying:
226    :1:
227    :abc       :
228    ::
229Test 1.6: Type: AFC.  Length: strlen+1
230  Querying:
231    :1:
232    :abc       :
233    ::
234
235
236*** NULL data tests against CHAR ***
237Test 2.1: Type: default.  Length: default
238  Querying:
239Test 2.2: Type: AFC.  Length: default
240  Querying:
241Test 2.3: Type: AFC:  Length: 0
242  Querying:
243Test 2.4: Type: AFC:  Length: strlen
244  Querying:
245Test 2.5: Type: AFC.  Length: strlen-1
246  Querying:
247Test 2.6: Type: AFC.  Length: strlen+1
248  Querying:
249
250
251*** Non-null Data Tests against VARCHAR2***
252Test 3.1: Type: default.  Length: default
253  Querying:
254    :2:
255    ::
256    :abc:
257Test 3.2: Type: AFC.  Length: default
258  Querying:
259    :2:
260    ::
261    :abc:
262Test 3.3: Type: AFC:  Length: 0
263  Querying:
264    :2:
265    ::
266    :abc:
267Test 3.4: Type: AFC:  Length: strlen
268  Querying:
269    :2:
270    ::
271    :abc:
272Test 3.5: Type: AFC.  Length: strlen-1
273  Querying:
274    :2:
275    ::
276    :abc:
277Test 3.6: Type: AFC.  Length: strlen+1
278  Querying:
279    :2:
280    ::
281    :abc:
282
283
284*** NULL data tests against VARCHAR2 ***
285Test 4.1: Type: default.  Length: default
286  Querying:
287Test 4.2: Type: AFC.  Length: default
288  Querying:
289Test 4.3: Type: AFC:  Length: 0
290  Querying:
291Test 4.4: Type: AFC:  Length: strlen
292  Querying:
293Test 4.5: Type: AFC.  Length: strlen-1
294  Querying:
295Test 4.6: Type: AFC.  Length: strlen+1
296  Querying:
297Done
298