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