jump to ::DBI::Sybase::MSSQL if we are using MSSQL through Sybase
[dbsrgits/DBIx-Class-Historic.git] / t / 74mssql.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
9
10 #warn "$dsn $user $pass";
11
12 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test'
13   unless ($dsn);
14
15 plan tests => 6;
16
17
18 my $schema = DBICTest::Schema->clone;
19 $schema->connection($dsn, $user, $pass);
20
21 my $dbh = $schema->storage->dbh;
22
23 isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::Sybase::MSSQL');
24
25 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
26     DROP TABLE artist");
27 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL
28     DROP TABLE cd");
29
30 $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);");
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);");
32 # Just to test compat shim, Auto is in Core
33 $schema->class('Artist')->load_components('PK::Auto::MSSQL');
34
35 # Test PK
36 my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
37 ok($new->artistid, "Auto-PK worked");
38
39 # Test LIMIT
40 for (1..6) {
41     $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } );
42 }
43
44 my $it = $schema->resultset('Artist')->search( { },
45     { rows     => 3,
46       offset   => 2,
47       order_by => 'artistid'
48     }
49 );
50
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
59 is( $it->count, 3, "LIMIT count ok" );
60 ok( $it->next->name, "iterator->next ok" );
61 $it->next;
62 $it->next;
63 is( $it->next, undef, "next past end of resultset ok" );
64
65 # clean up our mess
66 END {
67     $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist")
68         if $dbh;
69     $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd")
70         if $dbh;
71 }