Another candidate for somethingawful.com (fix left join-ed count)
[dbsrgits/DBIx-Class-Historic.git] / t / 746sybase.t
CommitLineData
a964a928 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
9
10plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test'
11 unless ($dsn && $user);
12
d29565e0 13plan tests => 12;
a964a928 14
15my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
16
b3f41261 17# start disconnected to test reconnection
a964a928 18$schema->storage->ensure_connected;
526dc858 19$schema->storage->_dbh->disconnect;
b3f41261 20
a964a928 21isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::Sybase' );
22
23$schema->storage->dbh_do (sub {
24 my ($storage, $dbh) = @_;
25 eval { $dbh->do("DROP TABLE artist") };
26 $dbh->do(<<'SQL');
d29565e0 27
a964a928 28CREATE TABLE artist (
d29565e0 29 artistid INT IDENTITY NOT NULL,
a964a928 30 name VARCHAR(100),
31 rank INT DEFAULT 13 NOT NULL,
d29565e0 32 charfield CHAR(10) NULL,
33 primary key(artistid)
a964a928 34)
35
36SQL
37
38});
39
40my %seen_id;
41
42# fresh $schema so we start unconnected
43$schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
44
45# test primary key handling
46my $new = $schema->resultset('Artist')->create({ name => 'foo' });
47ok($new->artistid > 0, "Auto-PK worked");
48
49$seen_id{$new->artistid}++;
50
51# test LIMIT support
52for (1..6) {
53 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
54 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
55 $seen_id{$new->artistid}++;
56}
57
d29565e0 58my $it;
59
60$it = $schema->resultset('Artist')->search( {}, {
a964a928 61 rows => 3,
62 order_by => 'artistid',
63});
64
65TODO: {
66 local $TODO = 'Sybase is very very fucked in the limit department';
67
68 is( $it->count, 3, "LIMIT count ok" );
69}
70
71# The iterator still works correctly with rows => 3, even though the sql is
72# fucked, very interesting.
73
74is( $it->next->name, "foo", "iterator->next ok" );
75$it->next;
76is( $it->next->name, "Artist 2", "iterator->next ok" );
77is( $it->next, undef, "next past end of resultset ok" );
78
79
80# clean up our mess
81END {
d29565e0 82 my $dbh = eval { $schema->storage->_dbh };
83 $dbh->do('DROP TABLE artist') if $dbh;
a964a928 84}
d29565e0 85