6 use DBIx::Class::Optional::Dependencies ();
10 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
12 if (not ($dsn && $user && $pass)) {
13 plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
14 'Warning: This test drops and creates a table called \'event\'';
17 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_oracle')
18 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_oracle');
21 # DateTime::Format::Oracle needs this set
22 $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
23 $ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF';
24 $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1';
25 $ENV{NLS_SORT} = "BINARY";
26 $ENV{NLS_COMP} = "BINARY";
28 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
30 # older oracles do not support a TIMESTAMP datatype
31 my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9
36 my $dbh = $schema->storage->dbh;
38 #$dbh->do("alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'");
41 $dbh->do("DROP TABLE event");
46 starts_at date NOT NULL,
47 created_on $timestamp_datatype NOT NULL,
48 varchar_date varchar(20),
49 varchar_datetime varchar(20),
56 # TODO is in effect for the rest of the tests
57 local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime support'
58 if ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9;
62 # insert a row to play with
63 my $new = $schema->resultset('Event')->create({ id => 1, starts_at => '06-MAY-07', created_on => '2009-05-03 21:17:18.5' });
64 is($new->id, 1, "insert sucessful");
66 my $event = $schema->resultset('Event')->find( 1 );
68 is( ref($event->starts_at), 'DateTime', "starts_at inflated ok");
70 is( $event->starts_at->month, 5, "DateTime methods work on inflated column");
72 is( ref($event->created_on), 'DateTime', "created_on inflated ok");
74 is( $event->created_on->nanosecond, 500_000_000, "DateTime methods work with nanosecond precision");
76 my $dt = DateTime->now();
77 $event->starts_at($dt);
78 $event->created_on($dt);
81 is( $event->starts_at->month, $dt->month, "deflate ok");
82 is( int $event->created_on->nanosecond, int $dt->nanosecond, "deflate ok with nanosecond precision");
86 $schema->storage->disconnect;
88 delete $ENV{NLS_DATE_FORMAT};
89 delete $ENV{NLS_TIMESTAMP_FORMAT};
91 $schema->connection($dsn, $user, $pass, {
92 on_connect_call => 'datetime_setup'
95 $dt = DateTime->now();
97 my $timestamp = $dt->clone;
98 $timestamp->set_nanosecond( int 500_000_000 );
100 $event = $schema->resultset('Event')->find( 1 );
101 $event->update({ starts_at => $dt, created_on => $timestamp });
103 $event = $schema->resultset('Event')->find(1);
105 is( $event->starts_at, $dt, 'DateTime round-trip as DATE' );
106 is( $event->created_on, $timestamp, 'DateTime round-trip as TIMESTAMP' );
108 is( int $event->created_on->nanosecond, int 500_000_000,
109 'TIMESTAMP nanoseconds survived' );
111 } 'dateteime operations executed correctly';
117 if($schema && (my $dbh = $schema->storage->dbh)) {
118 $dbh->do("DROP TABLE event");