Commit | Line | Data |
a964a928 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
8 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/}; |
9 | |
10 | plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' |
11 | unless ($dsn && $user); |
12 | |
d29565e0 |
13 | plan tests => 12; |
a964a928 |
14 | |
15 | my $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 |
21 | isa_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 |
28 | CREATE 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 | |
36 | SQL |
37 | |
38 | }); |
39 | |
40 | my %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 |
46 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
47 | ok($new->artistid > 0, "Auto-PK worked"); |
48 | |
49 | $seen_id{$new->artistid}++; |
50 | |
51 | # test LIMIT support |
52 | for (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 |
58 | my $it; |
59 | |
60 | $it = $schema->resultset('Artist')->search( {}, { |
a964a928 |
61 | rows => 3, |
62 | order_by => 'artistid', |
63 | }); |
64 | |
65 | TODO: { |
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 | |
74 | is( $it->next->name, "foo", "iterator->next ok" ); |
75 | $it->next; |
76 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
77 | is( $it->next, undef, "next past end of resultset ok" ); |
78 | |
79 | |
80 | # clean up our mess |
81 | END { |
d29565e0 |
82 | my $dbh = eval { $schema->storage->_dbh }; |
83 | $dbh->do('DROP TABLE artist') if $dbh; |
a964a928 |
84 | } |
d29565e0 |
85 | |