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