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