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