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