xref: /PHP-8.3/ext/oci8/tests/bind_sqltnum.phpt (revision a53e5617)
1--TEST--
2Bind with SQLT_NUM
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8preg_match('/^[[:digit:]]+/', oci_client_version(), $matches);
9if (!(isset($matches[0]) && $matches[0] >= 12)) {
10    die("skip works only with Oracle 12c or greater version of Oracle client libraries");
11}
12?>
13--FILE--
14<?php
15
16require __DIR__.'/connect.inc';
17
18// Initialization
19
20$stmtarray = array(
21    "drop table bind_sqltnum_tab",
22
23    "create table bind_sqltnum_tab (
24        id                number,
25        varchar2_t10      varchar2(10),
26        number_t          number,
27        number_t92        number(9,2))"
28);
29
30oci8_test_sql_execute($c, $stmtarray);
31
32function check_col($c, $colname, $id)
33{
34    $s = oci_parse($c, "select dump($colname) from bind_sqltnum_tab where id = :id");
35    oci_bind_by_name($s, ":id", $id);
36    oci_execute($s);
37    oci_fetch_all($s, $r);
38    var_dump($r);
39}
40
41
42// Run Test
43
44echo "Test 1 - baseline test\n";
45
46$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (100, :c2)");
47$c2 = "Hood";
48$r = oci_bind_by_name($s, ":c2", $c2, -1);
49if (!$r) {
50    $e = oci_error($s);
51    var_dump($e);
52}
53$r = oci_execute($s, OCI_DEFAULT);
54if (!$r) {
55    $e = oci_error($s);
56    var_dump($e);
57}
58
59$s = oci_parse($c, "select id, varchar2_t10 from bind_sqltnum_tab");
60oci_execute($s);
61oci_fetch_all($s, $data);
62var_dump($data);
63
64echo "Test 2 - SQLT_NUM to a VARCHAR2 column\n";
65
66$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (100, :c2)");
67$c2 = "Hood";
68$r = oci_bind_by_name($s, ":c2", $c2, -1, SQLT_NUM);
69if (!$r) {
70    $e = oci_error($s);
71    var_dump($e['message']);
72}
73$r = oci_execute($s, OCI_DEFAULT);
74if (!$r) {
75    $e = oci_error($s);
76    var_dump($e['message']);
77}
78
79echo "\nTEST41 wrong bind type SQLT_NUM\n";
80
81$c2 = "Hood41";
82$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, varchar2_t10) VALUES (41, :c2)");
83oci_bind_by_name($s, ":c2", $c2, -1, SQLT_NUM);
84oci_execute($s);
85
86echo "\nTEST42 insert numbers SQLT_NUM\n";
87
88$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (42, :n1)");
89$n1 = 42;
90oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
91oci_execute($s);
92
93check_col($c, 'number_t', 42);
94
95echo "\nTEST43 insert numbers SQLT_NUM\n";
96
97$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (43, :n1)");
98$n1 = 42.69;
99oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
100oci_execute($s);
101
102check_col($c, 'number_t', 43);
103
104echo "\nTEST44\n";
105
106$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (44, :n1)");
107$n1 = 0;
108oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
109oci_execute($s);
110
111check_col($c, 'number_t', 44);
112
113echo "\nTEST45\n";
114
115$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (45, :n1)");
116$n1 = -23;
117oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
118oci_execute($s);
119
120check_col($c, 'number_t', 45);
121
122echo "\nTEST46 insert numbers\n";
123
124$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (46, :n1)");
125$n1 = "-23";
126oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
127oci_execute($s);
128
129check_col($c, 'number_t', 46);
130
131echo "\nTEST47\n";
132
133$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t) VALUES (47, :n1)");
134$n1 = "23";
135oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
136oci_execute($s);
137
138check_col($c, 'number_t', 47);
139
140echo "\nTEST48\n";
141
142$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (48, :n1)");
143$n1 = 123.56;
144oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
145oci_execute($s);
146
147check_col($c, 'number_t92', 48);
148
149echo "\nTEST49\n";
150
151$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (49, :n1)");
152$n1 = "123.56";
153oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
154oci_execute($s);
155
156check_col($c, 'number_t92', 49);
157
158echo "\nTEST50\n";
159
160$s = oci_parse($c, "INSERT INTO bind_sqltnum_tab (id, number_t92) VALUES (50, :n1)");
161$n1 = "";
162oci_bind_by_name($s, ":n1", $n1, -1, SQLT_NUM);
163oci_execute($s);
164
165check_col($c, 'number_t92', 50);
166
167// Clean up
168
169$stmtarray = array(
170    "drop table bind_sqltnum_tab"
171);
172
173oci8_test_sql_execute($c, $stmtarray);
174
175?>
176--EXPECTF--
177Test 1 - baseline test
178array(2) {
179  ["ID"]=>
180  array(1) {
181    [0]=>
182    string(3) "100"
183  }
184  ["VARCHAR2_T10"]=>
185  array(1) {
186    [0]=>
187    string(4) "Hood"
188  }
189}
190Test 2 - SQLT_NUM to a VARCHAR2 column
191
192Warning: oci_execute(): ORA-12899: %s (%s: 40, %s: 10) in %sbind_sqltnum.php on line %d
193string(%d) "ORA-12899: %s"
194
195TEST41 wrong bind type SQLT_NUM
196
197Warning: oci_execute(): ORA-12899: %s "%s"."BIND_SQLTNUM_TAB"."VARCHAR2_T10" (%s: 40, %s: 10) in %sbind_sqltnum.php on line %d
198
199TEST42 insert numbers SQLT_NUM
200array(1) {
201  ["DUMP(NUMBER_T)"]=>
202  array(1) {
203    [0]=>
204    string(29) "Typ=2 Len=8: 42,0,0,0,0,0,0,0"
205  }
206}
207
208TEST43 insert numbers SQLT_NUM
209array(1) {
210  ["DUMP(NUMBER_T)"]=>
211  array(1) {
212    [0]=>
213    string(29) "Typ=2 Len=8: 42,0,0,0,0,0,0,0"
214  }
215}
216
217TEST44
218array(1) {
219  ["DUMP(NUMBER_T)"]=>
220  array(1) {
221    [0]=>
222    string(28) "Typ=2 Len=8: 0,0,0,0,0,0,0,0"
223  }
224}
225
226TEST45
227array(1) {
228  ["DUMP(NUMBER_T)"]=>
229  array(1) {
230    [0]=>
231    string(44) "Typ=2 Len=8: 233,255,255,255,255,255,255,255"
232  }
233}
234
235TEST46 insert numbers
236array(1) {
237  ["DUMP(NUMBER_T)"]=>
238  array(1) {
239    [0]=>
240    string(44) "Typ=2 Len=8: 233,255,255,255,255,255,255,255"
241  }
242}
243
244TEST47
245array(1) {
246  ["DUMP(NUMBER_T)"]=>
247  array(1) {
248    [0]=>
249    string(29) "Typ=2 Len=8: 23,0,0,0,0,0,0,0"
250  }
251}
252
253TEST48
254array(1) {
255  ["DUMP(NUMBER_T92)"]=>
256  array(1) {
257    [0]=>
258    string(16) "Typ=2 Len=1: 128"
259  }
260}
261
262TEST49
263array(1) {
264  ["DUMP(NUMBER_T92)"]=>
265  array(1) {
266    [0]=>
267    string(16) "Typ=2 Len=1: 128"
268  }
269}
270
271TEST50
272
273Warning: oci_execute(): ORA-01438: %s in %sbind_sqltnum.php on line %d
274array(1) {
275  ["DUMP(NUMBER_T92)"]=>
276  array(0) {
277  }
278}
279