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