7 use DBIx::Class::Storage::DBI::Sybase::DateTime;
9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
11 plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test'
12 unless ($dsn && $user);
16 my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
18 $schema->storage->ensure_connected;
19 isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::Sybase' );
21 $schema->storage->dbh_do (sub {
22 my ($storage, $dbh) = @_;
23 eval { $dbh->do("DROP TABLE artist") };
24 eval { $dbh->do("DROP TABLE track") };
27 artistid INT IDENTITY PRIMARY KEY,
29 rank INT DEFAULT 13 NOT NULL,
30 charfield CHAR(10) NULL
37 trackid INT IDENTITY PRIMARY KEY,
40 last_updated_on DATETIME,
48 # fresh $schema so we start unconnected
49 $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
51 # test primary key handling
52 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
53 ok($new->artistid > 0, "Auto-PK worked");
55 $seen_id{$new->artistid}++;
59 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
60 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
61 $seen_id{$new->artistid}++;
64 my $it = $schema->resultset('Artist')->search( {}, {
66 order_by => 'artistid',
70 local $TODO = 'Sybase is very very fucked in the limit department';
72 is( $it->count, 3, "LIMIT count ok" );
75 # The iterator still works correctly with rows => 3, even though the sql is
76 # fucked, very interesting.
78 is( $it->next->name, "foo", "iterator->next ok" );
80 is( $it->next->name, "Artist 2", "iterator->next ok" );
81 is( $it->next, undef, "next past end of resultset ok" );
83 # Test DateTime inflation
85 my $dt = DBIx::Class::Storage::DBI::Sybase::DateTime
86 ->parse_datetime('2004-08-21T14:36:48.080Z');
89 ok( $row = $schema->resultset('Track')->create({
90 last_updated_on => $dt,
93 ok( $row = $schema->resultset('Track')
94 ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
97 is( $row->updated_date, $dt, 'DateTime inflation works' );
101 if (my $dbh = eval { $schema->storage->_dbh }) {
102 $dbh->do('DROP TABLE artist');
103 $dbh->do('DROP TABLE track');