11 DBICTest::Schema->load_classes('EventSmallDT');
13 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
15 if (not ($dsn && $user)) {
17 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
18 "\nWarning: This test drops and creates a table called 'track'";
21 for (qw/test_rdbms_ase test_dt/) {
22 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ($_)
23 unless DBIx::Class::Optional::Dependencies->req_ok_for ($_);
28 'DBI::Sybase::ASE::NoBindVars',
32 for my $storage_type (@storage_types) {
33 $schema = DBICTest::Schema->clone;
35 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
36 $schema->storage_type("::$storage_type");
38 $schema->connection($dsn, $user, $pass, {
39 on_connect_call => 'datetime_setup',
42 my $guard = Scope::Guard->new(\&cleanup);
44 $schema->storage->ensure_connected;
46 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
48 eval { $schema->storage->dbh->do("DROP TABLE track") };
49 $schema->storage->dbh->do(<<"SQL");
51 trackid INT IDENTITY PRIMARY KEY,
54 last_updated_at DATETIME NULL
57 eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
58 $schema->storage->dbh->do(<<"SQL");
59 CREATE TABLE event_small_dt (
60 id INT IDENTITY PRIMARY KEY,
61 small_dt SMALLDATETIME NULL,
65 # coltype, column, source, pk, create_extra, datehash
79 nanosecond => 500000000,
81 ['SMALLDATETIME', # minute precision
95 for my $dt_type (@dt_types) {
96 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
98 ok(my $dt = DateTime->new($sample_dt));
101 ok( $row = $schema->resultset($source)->create({
105 ok( $row = $schema->resultset($source)
106 ->search({ $pk => $row->$pk }, { select => [$col] })
109 is( $row->$col, $dt, "$type roundtrip" );
111 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
112 'DateTime fractional portion roundtrip' )
113 if exists $sample_dt->{nanosecond};
116 # test a computed datetime column
117 eval { $schema->storage->dbh->do("DROP TABLE track") };
118 $schema->storage->dbh->do(<<"SQL");
120 trackid INT IDENTITY PRIMARY KEY,
123 title VARCHAR(100) NULL,
124 last_updated_on DATETIME NULL,
125 last_updated_at AS getdate(),
129 my $now = DateTime->now;
131 my $new_row = $schema->resultset('Track')->create({});
132 $new_row->discard_changes;
135 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
136 } 'getdate() computed column works';
143 if (my $dbh = eval { $schema->storage->dbh }) {
144 $dbh->do('DROP TABLE track');
145 $dbh->do('DROP TABLE event_small_dt');