8 use DBIx::Class::Optional::Dependencies ();
12 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt')
14 DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_ase')
15 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt')
16 && DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_ase');
18 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
20 if (not ($dsn && $user)) {
22 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
23 "\nWarning: This test drops and creates a table called 'track' and " .
27 DBICTest::Schema->load_classes('EventSmallDT');
31 'DBI::Sybase::ASE::NoBindVars',
35 for my $storage_type (@storage_types) {
36 $schema = DBICTest::Schema->clone;
38 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
39 $schema->storage_type("::$storage_type");
41 $schema->connection($dsn, $user, $pass, {
42 on_connect_call => 'datetime_setup',
45 my $guard = Scope::Guard->new(sub { cleanup($schema) } );
47 $schema->storage->ensure_connected;
49 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
51 eval { $schema->storage->dbh->do("DROP TABLE track") };
52 $schema->storage->dbh->do(<<"SQL");
54 trackid INT IDENTITY PRIMARY KEY,
57 last_updated_at DATETIME NULL
60 eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
61 $schema->storage->dbh->do(<<"SQL");
62 CREATE TABLE event_small_dt (
63 id INT IDENTITY PRIMARY KEY,
64 small_dt SMALLDATETIME NULL,
68 # coltype, column, source, pk, create_extra, datehash
82 nanosecond => 500000000,
84 ['SMALLDATETIME', # minute precision
98 for my $dt_type (@dt_types) {
99 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
101 ok(my $dt = DateTime->new($sample_dt));
104 ok( $row = $schema->resultset($source)->create({
108 ok( $row = $schema->resultset($source)
109 ->search({ $pk => $row->$pk }, { select => [$col] })
112 is( $row->$col, $dt, "$type roundtrip" );
114 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
115 'DateTime fractional portion roundtrip' )
116 if exists $sample_dt->{nanosecond};
119 # test a computed datetime column
120 eval { $schema->storage->dbh->do("DROP TABLE track") };
121 $schema->storage->dbh->do(<<"SQL");
123 trackid INT IDENTITY PRIMARY KEY,
126 title VARCHAR(100) NULL,
127 last_updated_on DATETIME NULL,
128 last_updated_at AS getdate(),
132 my $now = DateTime->now;
134 my $new_row = $schema->resultset('Track')->create({});
135 $new_row->discard_changes;
138 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
139 } 'getdate() computed column works';
147 if (my $dbh = eval { $schema->storage->dbh }) {
148 $dbh->do('DROP TABLE track');
149 $dbh->do('DROP TABLE event_small_dt');