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 require DBICTest::Schema;
28 DBICTest::Schema->load_classes('EventSmallDT');
32 'DBI::Sybase::ASE::NoBindVars',
36 for my $storage_type (@storage_types) {
37 $schema = DBICTest::Schema->clone;
39 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
40 $schema->storage_type("::$storage_type");
42 $schema->connection($dsn, $user, $pass, {
43 on_connect_call => 'datetime_setup',
46 my $guard = Scope::Guard->new(sub { cleanup($schema) } );
48 $schema->storage->ensure_connected;
50 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
52 eval { $schema->storage->dbh->do("DROP TABLE track") };
53 $schema->storage->dbh->do(<<"SQL");
55 trackid INT IDENTITY PRIMARY KEY,
58 last_updated_at DATETIME NULL
61 eval { $schema->storage->dbh->do("DROP TABLE event_small_dt") };
62 $schema->storage->dbh->do(<<"SQL");
63 CREATE TABLE event_small_dt (
64 id INT IDENTITY PRIMARY KEY,
65 small_dt SMALLDATETIME NULL,
69 # coltype, column, source, pk, create_extra, datehash
83 nanosecond => 500000000,
85 ['SMALLDATETIME', # minute precision
99 for my $dt_type (@dt_types) {
100 my ($type, $col, $source, $pk, $create_extra, $sample_dt) = @$dt_type;
102 ok(my $dt = DateTime->new($sample_dt));
105 ok( $row = $schema->resultset($source)->create({
109 ok( $row = $schema->resultset($source)
110 ->search({ $pk => $row->$pk }, { select => [$col] })
113 is( $row->$col, $dt, "$type roundtrip" );
115 cmp_ok( $row->$col->nanosecond, '==', $sample_dt->{nanosecond},
116 'DateTime fractional portion roundtrip' )
117 if exists $sample_dt->{nanosecond};
120 # test a computed datetime column
121 eval { $schema->storage->dbh->do("DROP TABLE track") };
122 $schema->storage->dbh->do(<<"SQL");
124 trackid INT IDENTITY PRIMARY KEY,
127 title VARCHAR(100) NULL,
128 last_updated_on DATETIME NULL,
129 last_updated_at AS getdate(),
133 my $now = DateTime->now;
135 my $new_row = $schema->resultset('Track')->create({});
136 $new_row->discard_changes;
139 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
140 } 'getdate() computed column works';
148 if (my $dbh = eval { $schema->storage->dbh }) {
149 $dbh->do('DROP TABLE track');
150 $dbh->do('DROP TABLE event_small_dt');