xref: /PHP-7.1/ext/oci8/tests/bind_char_1.phpt (revision 37652336)
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=.AL32UTF8
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:
226Test 1.6: Type: AFC.  Length: strlen+1
227  Querying:
228    :1:
229    :abc       :
230    ::
231
232
233*** NULL data tests against CHAR ***
234Test 2.1: Type: default.  Length: default
235  Querying:
236Test 2.2: Type: AFC.  Length: default
237  Querying:
238Test 2.3: Type: AFC:  Length: 0
239  Querying:
240Test 2.4: Type: AFC:  Length: strlen
241  Querying:
242Test 2.5: Type: AFC.  Length: strlen-1
243  Querying:
244Test 2.6: Type: AFC.  Length: strlen+1
245  Querying:
246
247
248*** Non-null Data Tests against VARCHAR2***
249Test 3.1: Type: default.  Length: default
250  Querying:
251    :2:
252    ::
253    :abc:
254Test 3.2: Type: AFC.  Length: default
255  Querying:
256    :2:
257    ::
258    :abc:
259Test 3.3: Type: AFC:  Length: 0
260  Querying:
261    :2:
262    ::
263    :abc:
264Test 3.4: Type: AFC:  Length: strlen
265  Querying:
266    :2:
267    ::
268    :abc:
269Test 3.5: Type: AFC.  Length: strlen-1
270  Querying:
271Test 3.6: Type: AFC.  Length: strlen+1
272  Querying:
273    :2:
274    ::
275    :abc:
276
277
278*** NULL data tests against VARCHAR2 ***
279Test 4.1: Type: default.  Length: default
280  Querying:
281Test 4.2: Type: AFC.  Length: default
282  Querying:
283Test 4.3: Type: AFC:  Length: 0
284  Querying:
285Test 4.4: Type: AFC:  Length: strlen
286  Querying:
287Test 4.5: Type: AFC.  Length: strlen-1
288  Querying:
289Test 4.6: Type: AFC.  Length: strlen+1
290  Querying:
291Done
292