Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
eef2ff6c |
7 | |
8 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/}; |
9 | |
10 | #warn "$dsn $user $pass"; |
11 | |
70350518 |
12 | plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' |
eef2ff6c |
13 | unless ($dsn); |
14 | |
15 | plan tests => 4; |
16 | |
81092e2d |
17 | my $storage_type = '::DBI::MSSQL'; |
18 | $storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/; |
19 | # Add more for others in the future when they exist (ODBC? ADO? JDBC?) |
20 | |
3ff5b740 |
21 | my $schema = DBICTest::Schema->clone; |
22 | $schema->storage_type($storage_type); |
23 | $schema->connection($dsn, $user, $pass); |
eef2ff6c |
24 | |
3ff5b740 |
25 | my $dbh = $schema->storage->dbh; |
eef2ff6c |
26 | |
27 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL |
28 | DROP TABLE artist"); |
29 | |
30 | $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));"); |
31 | |
3ff5b740 |
32 | # Just to test compat shim, Auto is in Core |
33 | $schema->class('Artist')->load_components('PK::Auto::MSSQL'); |
eef2ff6c |
34 | |
35 | # Test PK |
3ff5b740 |
36 | my $new = $schema->resultset('Artist')->create( { name => 'foo' } ); |
eef2ff6c |
37 | ok($new->artistid, "Auto-PK worked"); |
38 | |
39 | # Test LIMIT |
40 | for (1..6) { |
3ff5b740 |
41 | $schema->resultset('Artist')->create( { name => 'Artist ' . $_ } ); |
eef2ff6c |
42 | } |
43 | |
3ff5b740 |
44 | my $it = $schema->resultset('Artist')->search( { }, |
eef2ff6c |
45 | { rows => 3, |
46 | offset => 2, |
47 | order_by => 'artistid' |
48 | } |
49 | ); |
50 | |
51 | is( $it->count, 3, "LIMIT count ok" ); |
f48dd03f |
52 | ok( $it->next->name, "iterator->next ok" ); |
eef2ff6c |
53 | $it->next; |
54 | $it->next; |
55 | is( $it->next, undef, "next past end of resultset ok" ); |
56 | |
3ff5b740 |
57 | # clean up our mess |
58 | END { |
59 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist") |
60 | if $dbh; |
61 | } |