xref: /PHP-5.4/ext/oci8/tests/bind_number.phpt (revision c7a8bd6a)
1--TEST--
2Bind with NUMBER column variants
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--INI--
11precision = 14
12--FILE--
13<?php
14
15require(dirname(__FILE__).'/connect.inc');
16
17// Initialization
18
19$stmtarray = array(
20	"drop table bind_number_tab",
21	"create table bind_number_tab (
22					id				  number,
23					number_t6		  number(6),
24					float_t			  float,
25					binary_float_t	  binary_float,
26					binary_double_t	  binary_double,
27					decimal_t		  decimal,
28					integer_t		  integer)"
29);
30
31oci8_test_sql_execute($c, $stmtarray);
32
33function check_col($c, $colname, $id)
34{
35	$s = oci_parse($c, "select $colname from bind_number_tab where id = :id");
36	oci_bind_by_name($s, ":id", $id);
37	oci_execute($s);
38	oci_fetch_all($s, $r);
39	var_dump($r);
40}
41
42// Run Test
43
44echo "Test 1 - invalid number\n";
45
46$s = oci_parse($c, "INSERT INTO bind_number_tab (id, number_t6) VALUES (1, :n1)");
47$n1 = "Hello";
48oci_bind_by_name($s, ":n1", $n1);
49oci_execute($s);
50
51check_col($c, "number_t6", 1);
52
53echo "\nTEST66 insert a float\n";
54
55$s = oci_parse($c, "INSERT INTO bind_number_tab (id, float_t) VALUES (66, :f1)");
56$f1 = 123.456;
57oci_bind_by_name($s, ":f1", $f1);
58oci_execute($s);
59
60check_col($c, 'float_t', 66);
61
62echo "\nTEST67 insert a binary float\n";
63
64$s = oci_parse($c, "INSERT INTO bind_number_tab (id, binary_float_t) VALUES (67, :f1)");
65$f1 = 567.456;
66oci_bind_by_name($s, ":f1", $f1);
67oci_execute($s);
68
69check_col($c, 'binary_float_t', 67);
70
71echo "\nTEST69 insert a binary double\n";
72
73$s = oci_parse($c, "INSERT INTO bind_number_tab (id, binary_double_t) VALUES (69, :f1)");
74$f1 = 567.456;
75oci_bind_by_name($s, ":f1", $f1);
76oci_execute($s);
77
78check_col($c, 'binary_double_t', 69);
79
80echo "\nTEST71 insert a decimal\n";
81
82$s = oci_parse($c, "INSERT INTO bind_number_tab (id, decimal_t) VALUES (71, :f1)");
83$f1 = 123.789;
84oci_bind_by_name($s, ":f1", $f1);
85oci_execute($s);
86
87check_col($c, 'decimal_t', 71);
88
89echo "\nTEST72 insert a decimal\n";
90
91$s = oci_parse($c, "INSERT INTO bind_number_tab (id, decimal_t) VALUES (72, :f1)");
92$f1 = 123.789;
93oci_bind_by_name($s, ":f1", $f1, -1, SQLT_NUM);
94oci_execute($s);
95
96check_col($c, 'decimal_t', 72);
97
98echo "\nTEST73 insert a double\n";
99
100$s = oci_parse($c, "INSERT INTO bind_number_tab (id, binary_double_t) VALUES (73, :f1)");
101$f1 = 483.589;
102oci_bind_by_name($s, ":f1", $f1);
103oci_execute($s);
104
105check_col($c, 'binary_double_t', 73);
106
107echo "\nTEST75 insert a INTEGER\n";
108
109$s = oci_parse($c, "INSERT INTO bind_number_tab (id, integer_t) VALUES (75, :f1)");
110$f1 = 589;
111oci_bind_by_name($s, ":f1", $f1);
112oci_execute($s);
113
114check_col($c, 'integer_t', 75);
115
116echo "\nTEST76 insert a INTEGER\n";
117
118$s = oci_parse($c, "INSERT INTO bind_number_tab (id, integer_t) VALUES (76, :f1)");
119$f1 = 42;
120oci_bind_by_name($s, ":f1", $f1, -1, SQLT_INT);
121oci_execute($s);
122
123check_col($c, 'integer_t', 76);
124
125
126// Clean up
127
128$stmtarray = array(
129	"drop table bind_number_tab"
130);
131
132oci8_test_sql_execute($c, $stmtarray);
133
134?>
135===DONE===
136<?php exit(0); ?>
137--EXPECTF--
138Test 1 - invalid number
139
140Warning: oci_execute(): ORA-01722: %s in %sbind_number.php on line %d
141array(1) {
142  ["NUMBER_T6"]=>
143  array(0) {
144  }
145}
146
147TEST66 insert a float
148array(1) {
149  ["FLOAT_T"]=>
150  array(1) {
151    [0]=>
152    string(7) "123.456"
153  }
154}
155
156TEST67 insert a binary float
157array(1) {
158  ["BINARY_FLOAT_T"]=>
159  array(1) {
160    [0]=>
161    string(%r15|8%r) "%r(5.67455994E\+002|567.4560)%r"
162  }
163}
164
165TEST69 insert a binary double
166array(1) {
167  ["BINARY_DOUBLE_T"]=>
168  array(1) {
169    [0]=>
170    string(%r23|16%r) "%r(5.6745600000000002E\+002|567.456000000000)%r"
171  }
172}
173
174TEST71 insert a decimal
175array(1) {
176  ["DECIMAL_T"]=>
177  array(1) {
178    [0]=>
179    string(3) "124"
180  }
181}
182
183TEST72 insert a decimal
184array(1) {
185  ["DECIMAL_T"]=>
186  array(1) {
187    [0]=>
188    string(1) "0"
189  }
190}
191
192TEST73 insert a double
193array(1) {
194  ["BINARY_DOUBLE_T"]=>
195  array(1) {
196    [0]=>
197    string(%r12|16%r) "%r(4.83589E\+002|483.589000000000)%r"
198  }
199}
200
201TEST75 insert a INTEGER
202array(1) {
203  ["INTEGER_T"]=>
204  array(1) {
205    [0]=>
206    string(3) "589"
207  }
208}
209
210TEST76 insert a INTEGER
211array(1) {
212  ["INTEGER_T"]=>
213  array(1) {
214    [0]=>
215    string(2) "42"
216  }
217}
218===DONE===
219
220
221