6 use DBIx::Class::Optional::Dependencies ();
10 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_oracle')
11 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_oracle');
13 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
15 if (not ($dsn && $user && $pass)) {
16 plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
17 'Warning: This test drops and creates a table called \'event\'';
20 # DateTime::Format::Oracle needs this set
21 $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
22 $ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF';
23 $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1';
24 $ENV{NLS_SORT} = "BINARY";
25 $ENV{NLS_COMP} = "BINARY";
27 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
29 # older oracles do not support a TIMESTAMP datatype
30 my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9
35 my $dbh = $schema->storage->dbh;
37 #$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
40 $dbh->do("DROP TABLE event");
45 starts_at date NOT NULL,
46 created_on $timestamp_datatype NOT NULL,
47 varchar_date varchar(20),
48 varchar_datetime varchar(20),
55 # TODO is in effect for the rest of the tests
56 local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime support'
57 if ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9;
61 # insert a row to play with
62 my $new = $schema->resultset('Event')->create({ id => 1, starts_at => '06-MAY-07', created_on => '2009-05-03 21:17:18.5' });
63 is($new->id, 1, "insert sucessful");
65 my $event = $schema->resultset('Event')->find( 1 );
67 is( ref($event->starts_at), 'DateTime', "starts_at inflated ok");
69 is( $event->starts_at->month, 5, "DateTime methods work on inflated column");
71 is( ref($event->created_on), 'DateTime', "created_on inflated ok");
73 is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
75 my $dt = DateTime->now();
76 $event->starts_at($dt);
77 $event->created_on($dt);
80 is( $event->starts_at->month, $dt->month, "deflate ok");
81 is( int $event->created_on->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
85 $schema->storage->disconnect;
87 delete $ENV{NLS_DATE_FORMAT};
88 delete $ENV{NLS_TIMESTAMP_FORMAT};
90 $schema->connection($dsn, $user, $pass, {
91 on_connect_call => 'datetime_setup'
94 $dt = DateTime->now();
96 my $timestamp = $dt->clone;
97 $timestamp->set_nanosecond( int 500_000_000 );
99 $event = $schema->resultset('Event')->find( 1 );
100 $event->update({ starts_at => $dt, created_on => $timestamp });
102 $event = $schema->resultset('Event')->find(1);
104 is( $event->starts_at, $dt, 'DateTime round-trip as DATE' );
105 is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' );
107 is( int $event->created_on->nanosecond, int 500_000_000,
108 'TIMESTAMP nanoseconds survived' );
110 } 'dateteime operations executed correctly';
116 if($schema && (my $dbh = $schema->storage->dbh)) {
117 $dbh->do("DROP TABLE event");