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