1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt test_rdbms_oracle );
11 # DateTime::Format::Oracle needs this set
12 $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
13 $ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF';
14 $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1';
15 $ENV{NLS_SORT} = "BINARY";
16 $ENV{NLS_COMP} = "BINARY";
18 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
19 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
21 # older oracles do not support a TIMESTAMP datatype
22 my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9
27 my $dbh = $schema->storage->dbh;
29 #$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
32 $dbh->do("DROP TABLE event");
37 starts_at date NOT NULL,
38 created_on $timestamp_datatype NOT NULL,
39 varchar_date varchar(20),
40 varchar_datetime varchar(20),
47 # TODO is in effect for the rest of the tests
48 local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime support'
49 if ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9;
53 # insert a row to play with
54 my $new = $schema->resultset('Event')->create({ id => 1, starts_at => '06-MAY-07', created_on => '2009-05-03 21:17:18.5' });
55 is($new->id, 1, "insert sucessful");
57 my $event = $schema->resultset('Event')->find( 1 );
59 is( ref($event->starts_at), 'DateTime', "starts_at inflated ok");
61 is( $event->starts_at->month, 5, "DateTime methods work on inflated column");
63 is( ref($event->created_on), 'DateTime', "created_on inflated ok");
65 is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
67 my $dt = DateTime->now();
68 $event->starts_at($dt);
69 $event->created_on($dt);
72 is( $event->starts_at->month, $dt->month, "deflate ok");
73 is( int $event->created_on->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
77 $schema->storage->disconnect;
79 delete $ENV{NLS_DATE_FORMAT};
80 delete $ENV{NLS_TIMESTAMP_FORMAT};
82 $schema->connection($dsn, $user, $pass, {
83 on_connect_call => 'datetime_setup'
86 $dt = DateTime->now();
88 my $timestamp = $dt->clone;
89 $timestamp->set_nanosecond( int 500_000_000 );
91 $event = $schema->resultset('Event')->find( 1 );
92 $event->update({ starts_at => $dt, created_on => $timestamp });
94 $event = $schema->resultset('Event')->find(1);
96 is( $event->starts_at, $dt, 'DateTime round-trip as DATE' );
97 is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' );
99 is( int $event->created_on->nanosecond, int 500_000_000,
100 'TIMESTAMP nanoseconds survived' );
102 } 'dateteime operations executed correctly';
108 if($schema && (my $dbh = $schema->storage->_dbh)) {
109 $dbh->do("DROP TABLE event");