1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt test_rdbms_ase );
8 use DBIx::Class::_Util 'scope_guard';
12 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
14 DBICTest::Schema->load_classes('EventSmallDT');
18 'DBI::Sybase::ASE::NoBindVars',
22 for my $storage_type (@storage_types) {
23 $schema = DBICTest::Schema->clone;
25 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
26 $schema->storage_type("::$storage_type");
28 $schema->connection($dsn, $user, $pass, {
29 on_connect_call => 'datetime_setup',
32 my $guard = scope_guard { cleanup($schema) };
34 $schema->storage->ensure_connected;
36 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
38 eval { $schema->storage->dbh->do("DROP TABLE track") };
39 $schema->storage->dbh->do(<<"SQL");
41 trackid INT IDENTITY PRIMARY KEY,
44 last_updated_at DATETIME NULL
47 eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
48 $schema->storage->dbh->do(<<"SQL");
49 CREATE TABLE event_small_dt (
50 id INT IDENTITY PRIMARY KEY,
51 small_dt SMALLDATETIME NULL,
55 # coltype, column, source, pk, create_extra, datehash
69 nanosecond => 500000000,
71 ['SMALLDATETIME', # minute precision
85 for my $dt_type (@dt_types) {
86 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
88 ok(my $dt = DateTime->new($sample_dt));
91 ok( $row = $schema->resultset($source)->create({
95 ok( $row = $schema->resultset($source)
96 ->search({ $pk => $row->$pk }, { select => [$col] })
99 is( $row->$col, $dt, "$type roundtrip" );
101 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
102 'DateTime fractional portion roundtrip' )
103 if exists $sample_dt->{nanosecond};
106 # test a computed datetime column
107 eval { $schema->storage->dbh->do("DROP TABLE track") };
108 $schema->storage->dbh->do(<<"SQL");
110 trackid INT IDENTITY PRIMARY KEY,
113 title VARCHAR(100) NULL,
114 last_updated_on DATETIME NULL,
115 last_updated_at AS getdate(),
119 my $now = DateTime->now;
121 my $new_row = $schema->resultset('Track')->create({});
122 $new_row->discard_changes;
125 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
126 } 'getdate() computed column works';
134 if (my $dbh = eval { $schema->storage->dbh }) {
135 $dbh->do('DROP TABLE track');
136 $dbh->do('DROP TABLE event_small_dt');