7 use DateTime::Format::Sybase;
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);
14 plan tests => (18 + 4*2)*2;
18 'DBI::Sybase::NoBindVars',
22 for my $storage_type (@storage_types) {
23 $schema = DBICTest::Schema->clone;
25 unless ($storage_type eq 'DBI::Sybase') { # autodetect
26 $schema->storage_type("::$storage_type");
28 $schema->connection($dsn, $user, $pass, {AutoCommit => 1});
30 $schema->storage->ensure_connected;
32 isa_ok( $schema->storage, "DBIx::Class::Storage::$storage_type" );
34 $schema->storage->dbh_do (sub {
35 my ($storage, $dbh) = @_;
36 eval { $dbh->do("DROP TABLE artist") };
39 artistid INT IDENTITY PRIMARY KEY,
41 rank INT DEFAULT 13 NOT NULL,
42 charfield CHAR(10) NULL
49 # so we start unconnected
50 $schema->storage->disconnect;
52 # test primary key handling
53 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
54 ok($new->artistid > 0, "Auto-PK worked");
56 $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}++;
65 is ($schema->resultset('Artist')->count, 7, 'count(*) of whole table ok');
69 ## avoid quoting bug with NoBindVars for now
70 # my $it = $schema->resultset('Artist')->search({artistid => { '>' => 0 }}, {
72 my $it = $schema->resultset('Artist')->search({}, {
74 order_by => 'artistid',
77 is( $it->count, 3, "LIMIT count ok" );
79 is( $it->next->name, "foo", "iterator->next ok" );
81 is( $it->next->name, "Artist 2", "iterator->next ok" );
82 is( $it->next, undef, "next past end of resultset ok" );
85 $it = $schema->resultset('Artist')->search({}, {
88 order_by => 'artistid',
91 is( $it->count, 3, "LIMIT with offset count ok" );
93 is( $it->next->name, "Artist 3", "iterator->next ok" );
95 is( $it->next->name, "Artist 5", "iterator->next ok" );
96 is( $it->next, undef, "next past end of resultset ok" );
98 # now try a grouped count
99 $schema->resultset('Artist')->create({ name => 'Artist 6' })
102 $it = $schema->resultset('Artist')->search({}, {
106 is( $it->count, 7, 'COUNT of GROUP_BY ok' );
108 # Test DateTime inflation with DATETIME
110 ['DATETIME', '2004-08-21T14:36:48.080Z'],
111 ['SMALLDATETIME', '2004-08-21T14:36:00.000Z'], # minute precision
114 for my $dt_type (@dt_types) {
115 my ($type, $sample_dt) = @$dt_type;
117 eval { $schema->storage->dbh->do("DROP TABLE track") };
118 $schema->storage->dbh->do(<<"SQL");
120 trackid INT IDENTITY PRIMARY KEY,
123 last_updated_on $type,
126 ok(my $dt = DateTime::Format::Sybase->parse_datetime($sample_dt));
129 ok( $row = $schema->resultset('Track')->create({
130 last_updated_on => $dt,
133 ok( $row = $schema->resultset('Track')
134 ->search({ trackid => $row->trackid }, { select => ['last_updated_on'] })
137 is( $row->updated_date, $dt, 'DateTime inflation works' );
143 if (my $dbh = eval { $schema->storage->_dbh }) {
144 $dbh->do('DROP TABLE artist');
145 $dbh->do('DROP TABLE track');