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