X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fdatetime_oracle.t;h=26a5357770614a1fde17bfa7da13a9c28ad868cf;hb=3705e3b2801ea6a8f770b6f0c528b119bea92fe9;hp=40fa59ad134bff02f11f29e15045f5eea1965efe;hpb=2d124f0104ab775c3db4e272940cebb0b7111ea2;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/datetime_oracle.t b/t/inflate/datetime_oracle.t index 40fa59a..26a5357 100644 --- a/t/inflate/datetime_oracle.t +++ b/t/inflate/datetime_oracle.t @@ -1,39 +1,43 @@ use strict; -use warnings; +use warnings; use Test::More; +use Test::Exception; +use DBIx::Class::Optional::Dependencies (); use lib qw(t/lib); use DBICTest; +plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_oracle') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_oracle'); + my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_ORA_${_}" } qw/DSN USER PASS/}; if (not ($dsn && $user && $pass)) { plan skip_all => 'Set $ENV{DBICTEST_ORA_DSN}, _USER and _PASS to run this test. ' . 'Warning: This test drops and creates a table called \'track\''; } -else { - eval "use DateTime; use DateTime::Format::Oracle;"; - if ($@) { - plan skip_all => 'needs DateTime and DateTime::Format::Oracle for testing'; - } - else { - plan tests => 10; - } -} # DateTime::Format::Oracle needs this set $ENV{NLS_DATE_FORMAT} = 'DD-MON-YY'; $ENV{NLS_TIMESTAMP_FORMAT} = 'YYYY-MM-DD HH24:MI:SSXFF'; $ENV{NLS_LANG} = 'AMERICAN_AMERICA.WE8ISO8859P1'; +$ENV{NLS_SORT} = "BINARY"; +$ENV{NLS_COMP} = "BINARY"; my $schema = DBICTest::Schema->connect($dsn, $user, $pass); +# older oracles do not support a TIMESTAMP datatype +my $timestamp_datatype = ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9 + ? 'DATE' + : 'TIMESTAMP' +; + # Need to redefine the last_updated_on column my $col_metadata = $schema->class('Track')->column_info('last_updated_on'); $schema->class('Track')->add_column( 'last_updated_on' => { data_type => 'date' }); $schema->class('Track')->add_column( 'last_updated_at' => { - data_type => 'timestamp' }); + data_type => $timestamp_datatype }); my $dbh = $schema->storage->dbh; @@ -42,7 +46,13 @@ my $dbh = $schema->storage->dbh; eval { $dbh->do("DROP TABLE track"); }; -$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at TIMESTAMP, small_dt DATE)"); +$dbh->do("CREATE TABLE track (trackid NUMBER(12), cd NUMBER(12), position NUMBER(12), title VARCHAR(255), last_updated_on DATE, last_updated_at $timestamp_datatype)"); + +# TODO is in effect for the rest of the tests +local $TODO = 'FIXME - something odd is going on with Oracle < 9 datetime support' + if ($schema->storage->_server_info->{normalized_dbms_version}||0) < 9; + +lives_ok { # insert a row to play with my $new = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1', last_updated_on => '06-MAY-07', last_updated_at => '2009-05-03 21:17:18.5' }); @@ -94,10 +104,15 @@ is( $track->last_updated_at, $timestamp, 'DateTime round-trip as TIMESTAMP' ); is( int $track->last_updated_at->nanosecond, int 500_000_000, 'TIMESTAMP nanoseconds survived' ); +} 'dateteime operations executed correctly'; + +done_testing; + # clean up our mess END { - if($schema && ($dbh = $schema->storage->dbh)) { - $dbh->do("DROP TABLE track"); - } + if($schema && (my $dbh = $schema->storage->dbh)) { + $dbh->do("DROP TABLE track"); + } + undef $schema; }