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