X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fdatetime_sybase.t;h=f1ff6fcc9cea2d67c6ddd5f77d977030c3f9e999;hb=f3f6c13a8ed810cce53141b462f372140e2ab2cd;hp=24d0f07ea5de32cba54d0a4f68c9e24094db0741;hpb=d867eedaa703200d7f0bc329836e99b6bd22bc39;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/datetime_sybase.t b/t/inflate/datetime_sybase.t index 24d0f07..f1ff6fc 100644 --- a/t/inflate/datetime_sybase.t +++ b/t/inflate/datetime_sybase.t @@ -17,21 +17,18 @@ if (not ($dsn && $user)) { if ($@) { plan skip_all => 'needs DateTime and DateTime::Format::Sybase for testing'; } - else { - plan tests => (4 * 2 * 2) + 2; # (tests * dt_types * storage_types) + storage_tests - } } my @storage_types = ( - 'DBI::Sybase', - 'DBI::Sybase::NoBindVars', + 'DBI::Sybase::ASE', + 'DBI::Sybase::ASE::NoBindVars', ); my $schema; for my $storage_type (@storage_types) { $schema = DBICTest::Schema->clone; - unless ($storage_type eq 'DBI::Sybase') { # autodetect + unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect $schema->storage_type("::$storage_type"); } $schema->connection($dsn, $user, $pass, { @@ -57,9 +54,9 @@ for my $storage_type (@storage_types) { $schema->storage->dbh->do(<<"SQL"); CREATE TABLE track ( trackid INT IDENTITY PRIMARY KEY, - cd INT, - position INT, - $col $type, + cd INT NULL, + position INT NULL, + $col $type NULL ) SQL ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt)); @@ -73,10 +70,39 @@ SQL ->search({ trackid => $row->trackid }, { select => [$col] }) ->first ); - is( $row->$col, $dt, 'DateTime roundtrip' ); + is( $row->$col, $dt, "$type roundtrip" ); + + is( $row->$col->nanosecond, $dt->nanosecond, + 'fractional DateTime portion roundtrip' ) + if $dt->nanosecond > 0; } + + # test a computed datetime column + eval { $schema->storage->dbh->do("DROP TABLE track") }; + $schema->storage->dbh->do(<<"SQL"); +CREATE TABLE track ( + trackid INT IDENTITY PRIMARY KEY, + cd INT NULL, + position INT NULL, + title VARCHAR(100) NULL, + last_updated_on DATETIME NULL, + last_updated_at AS getdate(), + small_dt SMALLDATETIME NULL +) +SQL + + my $now = DateTime->now; + sleep 1; + my $new_row = $schema->resultset('Track')->create({}); + $new_row->discard_changes; + + lives_and { + cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1) + } 'getdate() computed column works'; } +done_testing; + # clean up our mess END { if (my $dbh = eval { $schema->storage->_dbh }) {