Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
54a9a088 |
2 | use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt test_rdbms_oracle ); |
cb551b07 |
3 | |
8f7e044c |
4 | use strict; |
68de9438 |
5 | use warnings; |
8f7e044c |
6 | |
7 | use Test::More; |
538878de |
8 | use Test::Exception; |
c0329273 |
9 | |
8f7e044c |
10 | use DBICTest; |
11 | |
8f7e044c |
12 | # DateTime::Format::Oracle needs this set |
13 | $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY'; |
abc914bd |
14 | $ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF'; |
f27af16d |
15 | $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1'; |
994dc91b |
16 | $ENV{NLS_SORT} = "BINARY"; |
17 | $ENV{NLS_COMP} = "BINARY"; |
8f7e044c |
18 | |
cb551b07 |
19 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; |
8f7e044c |
20 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
21 | |
538878de |
22 | # older oracles do not support a TIMESTAMP datatype |
23 | my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9 |
24 | ? 'DATE' |
25 | : 'TIMESTAMP' |
26 | ; |
27 | |
8f7e044c |
28 | my $dbh = $schema->storage->dbh; |
29 | |
abc914bd |
30 | #$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'"); |
31 | |
8f7e044c |
32 | eval { |
12b348d9 |
33 | $dbh->do("DROP TABLE event"); |
8f7e044c |
34 | }; |
12b348d9 |
35 | $dbh->do(<<EOS); |
36 | CREATE TABLE event ( |
37 | id number NOT NULL, |
38 | starts_at date NOT NULL, |
39 | created_on $timestamp_datatype NOT NULL, |
40 | varchar_date varchar(20), |
41 | varchar_datetime varchar(20), |
42 | skip_inflation date, |
43 | ts_without_tz date, |
44 | PRIMARY KEY (id) |
45 | ) |
46 | EOS |
538878de |
47 | |
4ca1fd6f |
48 | # TODO is in effect for the rest of the tests |
538878de |
49 | local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime support' |
50 | if ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9; |
4ca1fd6f |
51 | |
538878de |
52 | lives_ok { |
8f7e044c |
53 | |
54 | # insert a row to play with |
12b348d9 |
55 | my $new = $schema->resultset('Event')->create({ id => 1, starts_at => '06-MAY-07', created_on => '2009-05-03 21:17:18.5' }); |
56 | is($new->id, 1, "insert sucessful"); |
8f7e044c |
57 | |
12b348d9 |
58 | my $event = $schema->resultset('Event')->find( 1 ); |
8f7e044c |
59 | |
12b348d9 |
60 | is( ref($event->starts_at), 'DateTime', "starts_at inflated ok"); |
8f7e044c |
61 | |
12b348d9 |
62 | is( $event->starts_at->month, 5, "DateTime methods work on inflated column"); |
8f7e044c |
63 | |
12b348d9 |
64 | is( ref($event->created_on), 'DateTime', "created_on inflated ok"); |
abc914bd |
65 | |
12b348d9 |
66 | is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision"); |
abc914bd |
67 | |
8f7e044c |
68 | my $dt = DateTime->now(); |
12b348d9 |
69 | $event->starts_at($dt); |
70 | $event->created_on($dt); |
71 | $event->update; |
8f7e044c |
72 | |
12b348d9 |
73 | is( $event->starts_at->month, $dt->month, "deflate ok"); |
74 | is( int $event->created_on->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision"); |
8f7e044c |
75 | |
9900b569 |
76 | # test datetime_setup |
77 | |
78 | $schema->storage->disconnect; |
79 | |
80 | delete $ENV{NLS_DATE_FORMAT}; |
81 | delete $ENV{NLS_TIMESTAMP_FORMAT}; |
82 | |
83 | $schema->connection($dsn, $user, $pass, { |
84 | on_connect_call => 'datetime_setup' |
85 | }); |
86 | |
87 | $dt = DateTime->now(); |
88 | |
89 | my $timestamp = $dt->clone; |
5d3d8b2a |
90 | $timestamp->set_nanosecond( int 500_000_000 ); |
9900b569 |
91 | |
12b348d9 |
92 | $event = $schema->resultset('Event')->find( 1 ); |
93 | $event->update({ starts_at => $dt, created_on => $timestamp }); |
9900b569 |
94 | |
12b348d9 |
95 | $event = $schema->resultset('Event')->find(1); |
9900b569 |
96 | |
12b348d9 |
97 | is( $event->starts_at, $dt, 'DateTime round-trip as DATE' ); |
98 | is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' ); |
9900b569 |
99 | |
12b348d9 |
100 | is( int $event->created_on->nanosecond, int 500_000_000, |
5d3d8b2a |
101 | 'TIMESTAMP nanoseconds survived' ); |
102 | |
4ca1fd6f |
103 | } 'dateteime operations executed correctly'; |
538878de |
104 | |
68de9438 |
105 | done_testing; |
106 | |
8f7e044c |
107 | # clean up our mess |
108 | END { |
961d79db |
109 | if($schema && (my $dbh = $schema->storage->_dbh)) { |
12b348d9 |
110 | $dbh->do("DROP TABLE event"); |
65d35121 |
111 | } |
112 | undef $schema; |
8f7e044c |
113 | } |
114 | |