Commit | Line | Data |
a964a928 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
d1c7e853 |
5 | use Test::Exception; |
a964a928 |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
9 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/}; |
10 | |
11 | plan skip_all => 'Set $ENV{DBICTEST_SYBASE_DSN}, _USER and _PASS to run this test' |
12 | unless ($dsn && $user); |
13 | |
d1c7e853 |
14 | plan tests => 13; |
a964a928 |
15 | |
16 | my $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 |
22 | isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::Sybase' ); |
23 | |
d1c7e853 |
24 | my $dbh; |
25 | lives_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 |
34 | CREATE 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 | |
42 | SQL |
43 | |
44 | }); |
45 | |
46 | my %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 |
52 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
53 | ok($new->artistid > 0, "Auto-PK worked"); |
54 | |
55 | $seen_id{$new->artistid}++; |
56 | |
57 | # test LIMIT support |
58 | for (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 |
64 | my $it; |
65 | |
66 | $it = $schema->resultset('Artist')->search( {}, { |
a964a928 |
67 | rows => 3, |
68 | order_by => 'artistid', |
69 | }); |
70 | |
71 | TODO: { |
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 | |
80 | is( $it->next->name, "foo", "iterator->next ok" ); |
81 | $it->next; |
82 | is( $it->next->name, "Artist 2", "iterator->next ok" ); |
83 | is( $it->next, undef, "next past end of resultset ok" ); |
84 | |
85 | |
86 | # clean up our mess |
87 | END { |
d29565e0 |
88 | my $dbh = eval { $schema->storage->_dbh }; |
89 | $dbh->do('DROP TABLE artist') if $dbh; |
a964a928 |
90 | } |
d29565e0 |
91 | |