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 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_ase')
22 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_ase');
26 'DBI::Sybase::ASE::NoBindVars',
30 for my $storage_type (@storage_types) {
31 $schema = DBICTest::Schema->clone;
33 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
34 $schema->storage_type("::$storage_type");
36 $schema->connection($dsn, $user, $pass, {
37 on_connect_call => 'datetime_setup',
40 my $guard = Scope::Guard->new(\&cleanup);
42 $schema->storage->ensure_connected;
44 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
46 eval { $schema->storage->dbh->do("DROP TABLE track") };
47 $schema->storage->dbh->do(<<"SQL");
49 trackid INT IDENTITY PRIMARY KEY,
52 last_updated_at DATETIME NULL
55 eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
56 $schema->storage->dbh->do(<<"SQL");
57 CREATE TABLE event_small_dt (
58 id INT IDENTITY PRIMARY KEY,
59 small_dt SMALLDATETIME NULL,
63 # coltype, column, source, pk, create_extra, datehash
77 nanosecond => 500000000,
79 ['SMALLDATETIME', # minute precision
93 for my $dt_type (@dt_types) {
94 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
96 ok(my $dt = DateTime->new($sample_dt));
99 ok( $row = $schema->resultset($source)->create({
103 ok( $row = $schema->resultset($source)
104 ->search({ $pk => $row->$pk }, { select => [$col] })
107 is( $row->$col, $dt, "$type roundtrip" );
109 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
110 'DateTime fractional portion roundtrip' )
111 if exists $sample_dt->{nanosecond};
114 # test a computed datetime column
115 eval { $schema->storage->dbh->do("DROP TABLE track") };
116 $schema->storage->dbh->do(<<"SQL");
118 trackid INT IDENTITY PRIMARY KEY,
121 title VARCHAR(100) NULL,
122 last_updated_on DATETIME NULL,
123 last_updated_at AS getdate(),
127 my $now = DateTime->now;
129 my $new_row = $schema->resultset('Track')->create({});
130 $new_row->discard_changes;
133 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
134 } 'getdate() computed column works';
141 if (my $dbh = eval { $schema->storage->dbh }) {
142 $dbh->do('DROP TABLE track');
143 $dbh->do('DROP TABLE event_small_dt');