8 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/};
10 eval "use DateTime; use DateTime::Format::Oracle;";
12 plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing';
14 elsif (not ($dsn && $user && $pass)) {
15 plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' .
16 'Warning: This test drops and creates a table called \'track\'';
22 # DateTime::Format::Oracle needs this set
23 $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY';
25 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
27 # Need to redefine the last_updated_on column
28 my $col_metadata = $schema->class('Track')->column_info('last_updated_on');
29 $schema->class('Track')->add_column( 'last_updated_on' => {
30 data_type => 'date' });
32 my $dbh = $schema->storage->dbh;
35 $dbh->do("DROP TABLE track");
37 $dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE)");
39 # insert a row to play with
40 my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07' });
41 is($new->trackid, 1, "insert sucessful");
43 my $track = $schema->resultset('Track')->find( 1 );
45 is( ref($track->last_updated_on), 'DateTime', "last_updated_on inflated ok");
47 is( $track->last_updated_on->month, 5, "DateTime methods work on inflated column");
49 my $dt = DateTime->now();
50 $track->last_updated_on($dt);
53 is( $track->last_updated_on->month, $dt->month, "deflate ok");
58 $dbh->do("DROP TABLE track");