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 | |
70350518 |
10 | plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test' |
eef2ff6c |
11 | unless ($dsn); |
12 | |
651682ae |
13 | plan tests => 6; |
eef2ff6c |
14 | |
3ff5b740 |
15 | my $schema = DBICTest::Schema->clone; |
3ff5b740 |
16 | $schema->connection($dsn, $user, $pass); |
eef2ff6c |
17 | |
3ff5b740 |
18 | my $dbh = $schema->storage->dbh; |
eef2ff6c |
19 | |
98464041 |
20 | isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server'); |
651682ae |
21 | |
eef2ff6c |
22 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL |
23 | DROP TABLE artist"); |
b10cb676 |
24 | $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL |
25 | DROP TABLE cd"); |
eef2ff6c |
26 | |
a0dd8679 |
27 | $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);"); |
a1cb5921 |
28 | $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 |
29 | # Just to test compat shim, Auto is in Core |
30 | $schema->class('Artist')->load_components('PK::Auto::MSSQL'); |
eef2ff6c |
31 | |
32 | # Test PK |
3ff5b740 |
33 | my $new = $schema->resultset('Artist')->create( { name => 'foo' } ); |
eef2ff6c |
34 | ok($new->artistid, "Auto-PK worked"); |
35 | |
36 | # Test LIMIT |
37 | for (1..6) { |
5432c6ae |
38 | $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } ); |
eef2ff6c |
39 | } |
40 | |
3ff5b740 |
41 | my $it = $schema->resultset('Artist')->search( { }, |
eef2ff6c |
42 | { rows => 3, |
43 | offset => 2, |
44 | order_by => 'artistid' |
45 | } |
46 | ); |
47 | |
b4474f31 |
48 | # Test ? in data don't get treated as placeholders |
49 | my $cd = $schema->resultset('CD')->create( { |
50 | artist => 1, |
51 | title => 'Does this break things?', |
52 | year => 2007, |
53 | } ); |
54 | ok($cd->id, 'Not treating ? in data as placeholders'); |
55 | |
eef2ff6c |
56 | is( $it->count, 3, "LIMIT count ok" ); |
f48dd03f |
57 | ok( $it->next->name, "iterator->next ok" ); |
eef2ff6c |
58 | $it->next; |
59 | $it->next; |
60 | is( $it->next, undef, "next past end of resultset ok" ); |
61 | |
3ff5b740 |
62 | # clean up our mess |
63 | END { |
64 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist") |
65 | if $dbh; |
b4474f31 |
66 | $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd") |
67 | if $dbh; |
3ff5b740 |
68 | } |