xref: /PHP-8.0/ext/oci8/tests/bind_sqltint.phpt (revision f8d79582)
1--TEST--
2Bind with SQLT_INT
3--SKIPIF--
4<?php if (!extension_loaded('oci8')) die ("skip no oci8 extension"); ?>
5--FILE--
6<?php
7
8require(__DIR__.'/connect.inc');
9
10// Initialization
11
12$stmtarray = array(
13    "drop table bind_sqltint_tab",
14
15    "create table bind_sqltint_tab (
16        id                number,
17        varchar2_t10      varchar2(10),
18        number_t          number,
19        number_t92        number(9,2))",
20
21);
22
23oci8_test_sql_execute($c, $stmtarray);
24
25function check_col($c, $colname, $id)
26{
27    $s = oci_parse($c, "select $colname from bind_sqltint_tab where id = :id");
28    oci_bind_by_name($s, ":id", $id);
29    oci_execute($s);
30    oci_fetch_all($s, $r);
31    var_dump($r);
32}
33
34// Run Test
35
36echo "\nTEST141 wrong bind type SQLT_INT\n";
37
38$c2 = "Hood141";
39$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, varchar2_t10) VALUES (141, :c2)");
40oci_bind_by_name($s, ":c2", $c2, -1, SQLT_INT);
41oci_execute($s);
42
43check_col($c, 'varchar2_t10', 141);
44
45echo "\nTEST142 insert numbers SQLT_INT\n";
46
47$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t) VALUES (142, :n1)");
48$n1 = 42;
49oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
50oci_execute($s);
51
52check_col($c, 'number_t', 142);
53
54echo "\nTEST143 insert numbers, SQLT_INT\n";
55
56$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t) VALUES (143, :n1)");
57$n1 = 42.69;
58oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
59oci_execute($s);
60
61check_col($c, 'number_t', 143);
62
63echo "\nTEST144 insert numbers with SQLT_INT\n";
64
65$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t) VALUES (144, :n1)");
66$n1 = 0;
67oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
68oci_execute($s);
69
70check_col($c, 'number_t', 144);
71
72echo "\nTEST145 insert numbers with SQLT_INT\n";
73
74$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t) VALUES (145, :n1)");
75$n1 = -23;
76oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
77oci_execute($s);
78
79check_col($c, 'number_t', 145);
80
81echo "\nTEST146 insert numbers\n";
82
83$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t) VALUES (146, :n1)");
84$n1 = "-23";
85oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
86oci_execute($s);
87
88check_col($c, 'number_t', 146);
89
90echo "\nTEST147 insert numbers with SQLT_INT\n";
91
92$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t) VALUES (147, :n1)");
93$n1 = "23";
94oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
95oci_execute($s);
96
97check_col($c, 'number_t', 147);
98
99echo "\nTEST148 insert numbers with SQLT_INT\n";
100
101$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t92) VALUES (148, :n1)");
102$n1 = 123.56;
103oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
104oci_execute($s);
105
106check_col($c, 'number_t92', 148);
107
108echo "\nTEST149 insert numbers with SQLT_INT\n";
109
110$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t92) VALUES (149, :n1)");
111$n1 = "123.56";
112oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
113oci_execute($s);
114
115check_col($c, 'number_t92', 149);
116
117echo "\nTEST150 insert numbers with SQLT_INT\n";
118
119$s = oci_parse($c, "INSERT INTO bind_sqltint_tab (id, number_t92) VALUES (150, :n1)");
120$n1 = "";
121oci_bind_by_name($s, ":n1", $n1, -1, SQLT_INT);
122oci_execute($s);
123
124check_col($c, 'number_t92', 150);
125
126echo "\nTEST151 - 159 Initialization tests\n";
127
128$s = oci_parse($c, "begin :p2 := :p1; end;");
129unset($p1);
130unset($p2);
131oci_bind_by_name($s, ":p1", $p1, 10);
132oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
133oci_execute($s);
134var_dump($p2);
135
136echo "\nTEST152\n";
137
138unset($p1);
139$p2 = null;
140oci_bind_by_name($s, ":p1", $p1, 10);
141oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
142oci_execute($s);
143var_dump($p2);
144
145echo "\nTEST153\n";
146
147unset($p1);
148$p2 = 1111;
149oci_bind_by_name($s, ":p1", $p1, 10);
150oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
151oci_execute($s);
152var_dump($p2);
153
154echo "\nTEST154\n";
155
156$p1 = null;
157unset($p2);
158oci_bind_by_name($s, ":p1", $p1, 10);
159oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
160oci_execute($s);
161var_dump($p2);
162
163echo "\nTEST155\n";
164
165$p1 = null;
166$p2 = null;
167oci_bind_by_name($s, ":p1", $p1, 10);
168oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
169oci_execute($s);
170var_dump($p2);
171
172echo "\nTEST156\n";
173
174$p1 = null;
175$p2 = 2222;
176oci_bind_by_name($s, ":p1", $p1, 10);
177oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
178oci_execute($s);
179var_dump($p2);
180
181echo "\nTEST157\n";
182
183$p1 = 3333;
184unset($p2);
185oci_bind_by_name($s, ":p1", $p1, 10);
186oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
187oci_execute($s);
188var_dump($p2);
189
190echo "\nTEST158\n";
191
192$p1 = 4444;
193$p2 = null;
194oci_bind_by_name($s, ":p1", $p1, 10);
195oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
196oci_execute($s);
197var_dump($p2);
198
199echo "\nTEST159\n";
200
201$p1 = 5555;
202$p2 = 6666;
203oci_bind_by_name($s, ":p1", $p1, 10);
204oci_bind_by_name($s, ":p2", $p2, -1, SQLT_INT);
205oci_execute($s);
206var_dump($p2);
207
208// Clean up
209
210$stmtarray = array(
211    "drop table bind_sqltint_tab"
212);
213
214oci8_test_sql_execute($c, $stmtarray);
215
216?>
217--EXPECT--
218TEST141 wrong bind type SQLT_INT
219array(1) {
220  ["VARCHAR2_T10"]=>
221  array(1) {
222    [0]=>
223    string(1) "0"
224  }
225}
226
227TEST142 insert numbers SQLT_INT
228array(1) {
229  ["NUMBER_T"]=>
230  array(1) {
231    [0]=>
232    string(2) "42"
233  }
234}
235
236TEST143 insert numbers, SQLT_INT
237array(1) {
238  ["NUMBER_T"]=>
239  array(1) {
240    [0]=>
241    string(2) "42"
242  }
243}
244
245TEST144 insert numbers with SQLT_INT
246array(1) {
247  ["NUMBER_T"]=>
248  array(1) {
249    [0]=>
250    string(1) "0"
251  }
252}
253
254TEST145 insert numbers with SQLT_INT
255array(1) {
256  ["NUMBER_T"]=>
257  array(1) {
258    [0]=>
259    string(3) "-23"
260  }
261}
262
263TEST146 insert numbers
264array(1) {
265  ["NUMBER_T"]=>
266  array(1) {
267    [0]=>
268    string(3) "-23"
269  }
270}
271
272TEST147 insert numbers with SQLT_INT
273array(1) {
274  ["NUMBER_T"]=>
275  array(1) {
276    [0]=>
277    string(2) "23"
278  }
279}
280
281TEST148 insert numbers with SQLT_INT
282array(1) {
283  ["NUMBER_T92"]=>
284  array(1) {
285    [0]=>
286    string(3) "123"
287  }
288}
289
290TEST149 insert numbers with SQLT_INT
291array(1) {
292  ["NUMBER_T92"]=>
293  array(1) {
294    [0]=>
295    string(3) "123"
296  }
297}
298
299TEST150 insert numbers with SQLT_INT
300array(1) {
301  ["NUMBER_T92"]=>
302  array(1) {
303    [0]=>
304    string(1) "0"
305  }
306}
307
308TEST151 - 159 Initialization tests
309NULL
310
311TEST152
312NULL
313
314TEST153
315NULL
316
317TEST154
318NULL
319
320TEST155
321NULL
322
323TEST156
324NULL
325
326TEST157
327int(3333)
328
329TEST158
330int(4444)
331
332TEST159
333int(5555)
334