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