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'";
16 eval "use DateTime; use DateTime::Format::Sybase;";
18 plan skip_all => 'needs DateTime and DateTime::Format::Sybase for testing';
24 'DBI::Sybase::ASE::NoBindVars',
28 for my $storage_type (@storage_types) {
29 $schema = DBICTest::Schema->clone;
31 unless ($storage_type eq 'DBI::Sybase::ASE') { # autodetect
32 $schema->storage_type("::$storage_type");
34 $schema->connection($dsn, $user, $pass, {
36 on_connect_call => [ 'datetime_setup' ],
39 $schema->storage->ensure_connected;
41 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
45 ['DATETIME', 'last_updated_at', '2004-08-21T14:36:48.080Z'],
47 ['SMALLDATETIME', 'small_dt', '2004-08-21T14:36:00.000Z'],
50 for my $dt_type (@dt_types) {
51 my ($type, $col, $sample_dt) = @$dt_type;
53 eval { $schema->storage->dbh->do("DROP TABLE track") };
54 $schema->storage->dbh->do(<<"SQL");
56 trackid INT IDENTITY PRIMARY KEY,
62 ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
65 ok( $row = $schema->resultset('Track')->create({
69 ok( $row = $schema->resultset('Track')
70 ->search({ trackid => $row->trackid }, { select => [$col] })
73 is( $row->$col, $dt, 'DateTime roundtrip' );
76 # test a computed datetime column
77 eval { $schema->storage->dbh->do("DROP TABLE track") };
78 $schema->storage->dbh->do(<<"SQL");
80 trackid INT IDENTITY PRIMARY KEY,
83 title VARCHAR(100) NULL,
84 last_updated_on DATETIME NULL,
85 last_updated_at AS getdate(),
86 small_dt SMALLDATETIME NULL
90 my $now = DateTime->now;
92 my $new_row = $schema->resultset('Track')->create({});
93 $new_row->discard_changes;
96 cmp_ok (($new_row->last_updated_at - $now)->seconds, '>=', 1)
97 } 'getdate() computed column works';
104 if (my $dbh = eval { $schema->storage->_dbh }) {
105 $dbh->do('DROP TABLE track');