silence loud test
[dbsrgits/DBIx-Class-Historic.git] / t / 746mssql.t
CommitLineData
c1cac633 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PASS/};
9
10plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test'
11 unless ($dsn && $user);
12
13plan tests => 12;
14
15my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
16
17$schema->storage->ensure_connected;
18isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server' );
19
c5f77f6c 20$schema->storage->dbh_do (sub {
21 my ($storage, $dbh) = @_;
22 eval { $dbh->do("DROP TABLE artist") };
23 $dbh->do(<<'SQL');
c1cac633 24
c1cac633 25CREATE TABLE artist (
26 artistid INT IDENTITY NOT NULL,
a0dd8679 27 name VARCHAR(100),
39da2a2b 28 rank INT NOT NULL DEFAULT '13',
2eebd801 29 charfield CHAR(10) NULL,
c1cac633 30 primary key(artistid)
31)
32
c5f77f6c 33SQL
34
35});
36
c1cac633 37my %seen_id;
38
2eebd801 39# fresh $schema so we start unconnected
40$schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
41
c1cac633 42# test primary key handling
43my $new = $schema->resultset('Artist')->create({ name => 'foo' });
44ok($new->artistid > 0, "Auto-PK worked");
45
46$seen_id{$new->artistid}++;
47
48# test LIMIT support
49for (1..6) {
50 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
51 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
52 $seen_id{$new->artistid}++;
53}
54
55my $it = $schema->resultset('Artist')->search( {}, {
56 rows => 3,
57 order_by => 'artistid',
58});
59
60is( $it->count, 3, "LIMIT count ok" );
61is( $it->next->name, "foo", "iterator->next ok" );
62$it->next;
63is( $it->next->name, "Artist 2", "iterator->next ok" );
64is( $it->next, undef, "next past end of resultset ok" );
65
66
67# clean up our mess
68END {
c5f77f6c 69 my $dbh = eval { $schema->storage->_dbh };
c1cac633 70 $dbh->do('DROP TABLE artist') if $dbh;
71}
72