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