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