jump to ::DBI::Sybase::MSSQL if we are using MSSQL through Sybase
[dbsrgits/DBIx-Class-Historic.git] / t / 74mssql.t
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
eef2ff6c 7
8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_${_}" } qw/DSN USER PASS/};
9
10#warn "$dsn $user $pass";
11
70350518 12plan skip_all => 'Set $ENV{DBICTEST_MSSQL_DSN}, _USER and _PASS to run this test'
eef2ff6c 13 unless ($dsn);
14
651682ae 15plan tests => 6;
eef2ff6c 16
81092e2d 17
3ff5b740 18my $schema = DBICTest::Schema->clone;
3ff5b740 19$schema->connection($dsn, $user, $pass);
eef2ff6c 20
3ff5b740 21my $dbh = $schema->storage->dbh;
eef2ff6c 22
651682ae 23isa_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 36my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
eef2ff6c 37ok($new->artistid, "Auto-PK worked");
38
39# Test LIMIT
40for (1..6) {
5432c6ae 41 $schema->resultset('Artist')->create( { name => 'Artist ' . $_, rank => $_ } );
eef2ff6c 42}
43
3ff5b740 44my $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
52my $cd = $schema->resultset('CD')->create( {
53 artist => 1,
54 title => 'Does this break things?',
55 year => 2007,
56} );
57ok($cd->id, 'Not treating ? in data as placeholders');
58
eef2ff6c 59is( $it->count, 3, "LIMIT count ok" );
f48dd03f 60ok( $it->next->name, "iterator->next ok" );
eef2ff6c 61$it->next;
62$it->next;
63is( $it->next, undef, "next past end of resultset ok" );
64
3ff5b740 65# clean up our mess
66END {
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}