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