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 | |
651682ae |
15 | plan tests => 6; |
eef2ff6c |
16 | |
81092e2d |
17 | |
3ff5b740 |
18 | my $schema = DBICTest::Schema->clone; |
3ff5b740 |
19 | $schema->connection($dsn, $user, $pass); |
eef2ff6c |
20 | |
3ff5b740 |
21 | my $dbh = $schema->storage->dbh; |
eef2ff6c |
22 | |
651682ae |
23 | isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::Sybase::MSSQL'); |
24 | |
eef2ff6c |
25 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL |
26 | DROP TABLE artist"); |
b10cb676 |
27 | $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL |
28 | DROP TABLE cd"); |
eef2ff6c |
29 | |
a0dd8679 |
30 | $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);"); |
a1cb5921 |
31 | $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 |
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) { |
5432c6ae |
41 | $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } ); |
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 | |
b4474f31 |
51 | # Test ? in data don't get treated as placeholders |
52 | my $cd = $schema->resultset('CD')->create( { |
53 | artist => 1, |
54 | title => 'Does this break things?', |
55 | year => 2007, |
56 | } ); |
57 | ok($cd->id, 'Not treating ? in data as placeholders'); |
58 | |
eef2ff6c |
59 | is( $it->count, 3, "LIMIT count ok" ); |
f48dd03f |
60 | ok( $it->next->name, "iterator->next ok" ); |
eef2ff6c |
61 | $it->next; |
62 | $it->next; |
63 | is( $it->next, undef, "next past end of resultset ok" ); |
64 | |
3ff5b740 |
65 | # clean up our mess |
66 | END { |
67 | $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist") |
68 | if $dbh; |
b4474f31 |
69 | $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd") |
70 | if $dbh; |
3ff5b740 |
71 | } |