9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
11 if (not ($dsn && $user)) {
13 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' .
14 "\nWarning: This test drops and creates a table called 'track'";
17 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_rdbms_ase')
18 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_rdbms_ase');
22 'DBI::Sybase::ASE::NoBindVars',
26 for my $storage_type (@storage_types) {
27 $schema = DBICTest::Schema->clone;
29 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
30 $schema->storage_type("::$storage_type");
32 $schema->connection($dsn, $user, $pass, {
34 on_connect_call => [ 'datetime_setup' ],
37 $schema->storage->ensure_connected;
39 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
43 ['DATETIME', 'last_updated_at', '2004-08-21T14:36:48.080Z'],
45 ['SMALLDATETIME', 'small_dt', '2004-08-21T14:36:00.000Z'],
48 for my $dt_type (@dt_types) {
49 my ($type, $col, $sample_dt) = @$dt_type;
51 eval { $schema->storage->dbh->do("DROP TABLE track") };
52 $schema->storage->dbh->do(<<"SQL");
54 trackid INT IDENTITY PRIMARY KEY,
60 ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
63 ok( $row = $schema->resultset('Track')->create({
67 ok( $row = $schema->resultset('Track')
68 ->search({ trackid => $row->trackid }, { select => [$col] })
71 is( $row->$col, $dt, "$type roundtrip" );
73 is( $row->$col->nanosecond, $dt->nanosecond,
74 'fractional DateTime portion roundtrip' )
75 if $dt->nanosecond > 0;
78 # test a computed datetime column
79 eval { $schema->storage->dbh->do("DROP TABLE track") };
80 $schema->storage->dbh->do(<<"SQL");
82 trackid INT IDENTITY PRIMARY KEY,
85 title VARCHAR(100) NULL,
86 last_updated_on DATETIME NULL,
87 last_updated_at AS getdate(),
88 small_dt SMALLDATETIME NULL
92 my $now = DateTime->now;
94 my $new_row = $schema->resultset('Track')->create({});
95 $new_row->discard_changes;
98 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
99 } 'getdate() computed column works';
106 if (my $dbh = eval { $schema->storage->_dbh }) {
107 $dbh->do('DROP TABLE track');