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 | |
b4474f31 |
15 | plan tests => 5; |
eef2ff6c |
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"); |
b10cb676 |
29 | $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL |
30 | DROP TABLE cd"); |
eef2ff6c |
31 | |
a0dd8679 |
32 | $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);"); |
a1cb5921 |
33 | $dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100), genreid INT NULL, single_track INT NULL);"); |
3ff5b740 |
34 | # Just to test compat shim, Auto is in Core |
35 | $schema->class('Artist')->load_components('PK::Auto::MSSQL'); |
eef2ff6c |
36 | |
37 | # Test PK |
3ff5b740 |
38 | my $new = $schema->resultset('Artist')->create( { name => 'foo' } ); |
eef2ff6c |
39 | ok($new->artistid, "Auto-PK worked"); |
40 | |
41 | # Test LIMIT |
42 | for (1..6) { |
3ff5b740 |
43 | $schema->resultset('Artist')->create( { name => 'Artist ' . $_ } ); |
eef2ff6c |
44 | } |
45 | |
3ff5b740 |
46 | my $it = $schema->resultset('Artist')->search( { }, |
eef2ff6c |
47 | { rows => 3, |
48 | offset => 2, |
49 | order_by => 'artistid' |
50 | } |
51 | ); |
52 | |
b4474f31 |
53 | # Test ? in data don't get treated as placeholders |
54 | my $cd = $schema->resultset('CD')->create( { |
55 | artist => 1, |
56 | title => 'Does this break things?', |
57 | year => 2007, |
58 | } ); |
59 | ok($cd->id, 'Not treating ? in data as placeholders'); |
60 | |
eef2ff6c |
61 | is( $it->count, 3, "LIMIT count ok" ); |
f48dd03f |
62 | ok( $it->next->name, "iterator->next ok" ); |
eef2ff6c |
63 | $it->next; |
64 | $it->next; |
65 | is( $it->next, undef, "next past end of resultset ok" ); |
66 | |
3ff5b740 |
67 | # clean up our mess |
68 | END { |
69 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist") |
70 | if $dbh; |
b4474f31 |
71 | $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd") |
72 | if $dbh; |
3ff5b740 |
73 | } |