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