1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt test_rdbms_oracle );
12 # DateTime::Format::Oracle needs this set
13 $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
14 $ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF';
15 $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1';
16 $ENV{NLS_SORT} = "BINARY";
17 $ENV{NLS_COMP} = "BINARY";
19 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
20 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
22 # older oracles do not support a TIMESTAMP datatype
23 my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9
28 my $dbh = $schema->storage->dbh;
30 #$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
33 $dbh->do("DROP TABLE event");
38 starts_at date NOT NULL,
39 created_on $timestamp_datatype NOT NULL,
40 varchar_date varchar(20),
41 varchar_datetime varchar(20),
48 # TODO is in effect for the rest of the tests
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;
54 # insert a row to play with
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");
58 my $event = $schema->resultset('Event')->find( 1 );
60 is( ref($event->starts_at), 'DateTime', "starts_at inflated ok");
62 is( $event->starts_at->month, 5, "DateTime methods work on inflated column");
64 is( ref($event->created_on), 'DateTime', "created_on inflated ok");
66 is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
68 my $dt = DateTime->now();
69 $event->starts_at($dt);
70 $event->created_on($dt);
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");
78 $schema->storage->disconnect;
80 delete $ENV{NLS_DATE_FORMAT};
81 delete $ENV{NLS_TIMESTAMP_FORMAT};
83 $schema->connection($dsn, $user, $pass, {
84 on_connect_call => 'datetime_setup'
87 $dt = DateTime->now();
89 my $timestamp = $dt->clone;
90 $timestamp->set_nanosecond( int 500_000_000 );
92 $event = $schema->resultset('Event')->find( 1 );
93 $event->update({ starts_at => $dt, created_on => $timestamp });
95 $event = $schema->resultset('Event')->find(1);
97 is( $event->starts_at, $dt, 'DateTime round-trip as DATE' );
98 is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' );
100 is( int $event->created_on->nanosecond, int 500_000_000,
101 'TIMESTAMP nanoseconds survived' );
103 } 'dateteime operations executed correctly';
109 if($schema && (my $dbh = $schema->storage->_dbh)) {
110 $dbh->do("DROP TABLE event");