1 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt test_rdbms_ase );
13 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
15 DBICTest::Schema->load_classes('EventSmallDT');
19 'DBI::Sybase::ASE::NoBindVars',
23 for my $storage_type (@storage_types) {
24 $schema = DBICTest::Schema->clone;
26 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
27 $schema->storage_type("::$storage_type");
29 $schema->connection($dsn, $user, $pass, {
30 on_connect_call => 'datetime_setup',
33 my $guard = Scope::Guard->new(sub { cleanup($schema) } );
35 $schema->storage->ensure_connected;
37 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
39 eval { $schema->storage->dbh->do("DROP TABLE track") };
40 $schema->storage->dbh->do(<<"SQL");
42 trackid INT IDENTITY PRIMARY KEY,
45 last_updated_at DATETIME NULL
48 eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
49 $schema->storage->dbh->do(<<"SQL");
50 CREATE TABLE event_small_dt (
51 id INT IDENTITY PRIMARY KEY,
52 small_dt SMALLDATETIME NULL,
56 # coltype, column, source, pk, create_extra, datehash
70 nanosecond => 500000000,
72 ['SMALLDATETIME', # minute precision
86 for my $dt_type (@dt_types) {
87 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
89 ok(my $dt = DateTime->new($sample_dt));
92 ok( $row = $schema->resultset($source)->create({
96 ok( $row = $schema->resultset($source)
97 ->search({ $pk => $row->$pk }, { select => [$col] })
100 is( $row->$col, $dt, "$type roundtrip" );
102 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
103 'DateTime fractional portion roundtrip' )
104 if exists $sample_dt->{nanosecond};
107 # test a computed datetime column
108 eval { $schema->storage->dbh->do("DROP TABLE track") };
109 $schema->storage->dbh->do(<<"SQL");
111 trackid INT IDENTITY PRIMARY KEY,
114 title VARCHAR(100) NULL,
115 last_updated_on DATETIME NULL,
116 last_updated_at AS getdate(),
120 my $now = DateTime->now;
122 my $new_row = $schema->resultset('Track')->create({});
123 $new_row->discard_changes;
126 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
127 } 'getdate() computed column works';
135 if (my $dbh = eval { $schema->storage->dbh }) {
136 $dbh->do('DROP TABLE track');
137 $dbh->do('DROP TABLE event_small_dt');