Patch for ? in NoBindVars data from Tom Hukins
[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
b4474f31 15plan tests => 5;
eef2ff6c 16
81092e2d 17my $storage_type = '::DBI::MSSQL';
18$storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/;
19# Add more for others in the future when they exist (ODBC? ADO? JDBC?)
20
3ff5b740 21my $schema = DBICTest::Schema->clone;
22$schema->storage_type($storage_type);
23$schema->connection($dsn, $user, $pass);
eef2ff6c 24
3ff5b740 25my $dbh = $schema->storage->dbh;
eef2ff6c 26
27$dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
28 DROP TABLE artist");
29
30$dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));");
b4474f31 31$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100));");
eef2ff6c 32
3ff5b740 33# Just to test compat shim, Auto is in Core
34$schema->class('Artist')->load_components('PK::Auto::MSSQL');
eef2ff6c 35
36# Test PK
3ff5b740 37my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
eef2ff6c 38ok($new->artistid, "Auto-PK worked");
39
40# Test LIMIT
41for (1..6) {
3ff5b740 42 $schema->resultset('Artist')->create( { name => 'Artist ' . $_ } );
eef2ff6c 43}
44
3ff5b740 45my $it = $schema->resultset('Artist')->search( { },
eef2ff6c 46 { rows => 3,
47 offset => 2,
48 order_by => 'artistid'
49 }
50);
51
b4474f31 52# Test ? in data don't get treated as placeholders
53my $cd = $schema->resultset('CD')->create( {
54 artist => 1,
55 title => 'Does this break things?',
56 year => 2007,
57} );
58ok($cd->id, 'Not treating ? in data as placeholders');
59
eef2ff6c 60is( $it->count, 3, "LIMIT count ok" );
f48dd03f 61ok( $it->next->name, "iterator->next ok" );
eef2ff6c 62$it->next;
63$it->next;
64is( $it->next, undef, "next past end of resultset ok" );
65
3ff5b740 66# clean up our mess
67END {
68 $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist")
69 if $dbh;
b4474f31 70 $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd")
71 if $dbh;
3ff5b740 72}