Tests and test schema adjustments for resultset update/delete
[dbsrgits/DBIx-Class.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
13plan tests => 12;
14
15my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
16
17$schema->storage->ensure_connected;
18isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::Sybase' );
19
20$schema->storage->dbh_do (sub {
21 my ($storage, $dbh) = @_;
22 eval { $dbh->do("DROP TABLE artist") };
23 $dbh->do(<<'SQL');
24
25CREATE TABLE artist (
26 artistid INT IDENTITY NOT NULL,
27 name VARCHAR(100),
28 rank INT DEFAULT 13 NOT NULL,
29 charfield CHAR(10) NULL,
30 primary key(artistid)
31)
32
33SQL
34
35});
36
37my %seen_id;
38
39# fresh $schema so we start unconnected
40$schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
41
42# test primary key handling
43my $new = $schema->resultset('Artist')->create({ name => 'foo' });
44ok($new->artistid > 0, "Auto-PK worked");
45
46$seen_id{$new->artistid}++;
47
48# test LIMIT support
49for (1..6) {
50 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
51 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
52 $seen_id{$new->artistid}++;
53}
54
55my $it;
56
57$it = $schema->resultset('Artist')->search( {}, {
58 rows => 3,
59 order_by => 'artistid',
60});
61
62TODO: {
63 local $TODO = 'Sybase is very very fucked in the limit department';
64
65 is( $it->count, 3, "LIMIT count ok" );
66}
67
68# The iterator still works correctly with rows => 3, even though the sql is
69# fucked, very interesting.
70
71is( $it->next->name, "foo", "iterator->next ok" );
72$it->next;
73is( $it->next->name, "Artist 2", "iterator->next ok" );
74is( $it->next, undef, "next past end of resultset ok" );
75
76
77# clean up our mess
78END {
79 my $dbh = eval { $schema->storage->_dbh };
80 $dbh->do('DROP TABLE artist') if $dbh;
81}
82