xref: /PHP-8.1/ext/oci8/tests/bug42173.phpt (revision b5a14e6c)
1--TEST--
2Bug #42173 (TIMESTAMP and INTERVAL query and field functions)
3--EXTENSIONS--
4oci8
5--SKIPIF--
6<?php
7$target_dbs = array('oracledb' => true, 'timesten' => false);  // test runs on these DBs
8require(__DIR__.'/skipif.inc');
9?>
10--FILE--
11<?php
12
13require(__DIR__.'/connect.inc');
14
15$stmts = array(
16
17"drop table ts_test",
18
19"create table ts_test (
20c1 TIMESTAMP,
21c2 TIMESTAMP (5),
22c3 TIMESTAMP WITH TIME ZONE,
23c4 TIMESTAMP (2) WITH TIME ZONE,
24c5 TIMESTAMP WITH LOCAL TIME ZONE,
25c6 INTERVAL YEAR TO MONTH,
26c7 INTERVAL YEAR(2) TO MONTH,
27c8 INTERVAL DAY TO SECOND,
28c9 INTERVAL DAY(2) TO SECOND(3)
29)",
30
31"insert into ts_test values (
32timestamp'1999-01-03 10:00:00.123',
33timestamp'1999-01-04 10:00:00.123456',
34timestamp'1999-01-05 10:00:00.123456+1:0',
35timestamp'1999-01-06 10:00:00.123456-1:0',
36timestamp'1999-01-06 10:00:00.123456-1:0',
37interval'1-2' year to month,
38interval'10-4' year to month,
39interval'1 2:20:20.123' day to second,
40interval'1 2:20:20.12345' day to second)");
41
42foreach ($stmts as $sql) {
43    $s = oci_parse($c, $sql);
44    $r = @oci_execute($s);
45}
46
47$s = oci_parse($c, "select * from ts_test");
48$r = oci_execute($s);
49$row = oci_fetch_array($s, OCI_ASSOC);
50var_dump($row);
51
52foreach ($row as $name => $field) {
53    echo "\nColumn $name\n";
54    var_dump(oci_field_is_null($s, $name));
55    var_dump(oci_field_name($s, $name));
56    var_dump(oci_field_type($s, $name));
57    var_dump(oci_field_type_raw($s, $name));
58    var_dump(oci_field_scale($s, $name));
59    var_dump(oci_field_precision($s, $name));
60    var_dump(oci_field_size($s, $name));
61}
62
63// Cleanup
64
65$s = oci_parse($c, "drop table ts_test");
66$r = @oci_execute($s);
67
68echo "Done\n";
69
70?>
71--EXPECTF--
72array(9) {
73  ["C1"]=>
74  string(28) "03-JAN-99 10.00.00.123000 AM"
75  ["C2"]=>
76  string(27) "04-JAN-99 10.00.00.12346 AM"
77  ["C3"]=>
78  string(35) "05-JAN-99 10.00.00.123456 AM +01:00"
79  ["C4"]=>
80  string(31) "06-JAN-99 10.00.00.12 AM -01:00"
81  ["C5"]=>
82  string(28) "%s"
83  ["C6"]=>
84  string(6) "+01-02"
85  ["C7"]=>
86  string(6) "+10-04"
87  ["C8"]=>
88  string(19) "+01 02:20:20.123000"
89  ["C9"]=>
90  string(16) "+01 02:20:20.123"
91}
92
93Column C1
94bool(false)
95string(2) "C1"
96string(9) "TIMESTAMP"
97int(187)
98int(6)
99int(0)
100int(11)
101
102Column C2
103bool(false)
104string(2) "C2"
105string(9) "TIMESTAMP"
106int(187)
107int(5)
108int(0)
109int(11)
110
111Column C3
112bool(false)
113string(2) "C3"
114string(23) "TIMESTAMP WITH TIMEZONE"
115int(188)
116int(6)
117int(0)
118int(13)
119
120Column C4
121bool(false)
122string(2) "C4"
123string(23) "TIMESTAMP WITH TIMEZONE"
124int(188)
125int(2)
126int(0)
127int(13)
128
129Column C5
130bool(false)
131string(2) "C5"
132string(29) "TIMESTAMP WITH LOCAL TIMEZONE"
133int(232)
134int(6)
135int(0)
136int(11)
137
138Column C6
139bool(false)
140string(2) "C6"
141string(22) "INTERVAL YEAR TO MONTH"
142int(189)
143int(0)
144int(2)
145int(5)
146
147Column C7
148bool(false)
149string(2) "C7"
150string(22) "INTERVAL YEAR TO MONTH"
151int(189)
152int(0)
153int(2)
154int(5)
155
156Column C8
157bool(false)
158string(2) "C8"
159string(22) "INTERVAL DAY TO SECOND"
160int(190)
161int(6)
162int(2)
163int(11)
164
165Column C9
166bool(false)
167string(2) "C9"
168string(22) "INTERVAL DAY TO SECOND"
169int(190)
170int(3)
171int(2)
172int(11)
173Done
174