new config option to DBICTest to let you set an alternative storage type, start on...
[dbsrgits/DBIx-Class.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
20my $dbh = $schema->storage->dbh;
21
22eval { $dbh->do("DROP TABLE artist") };
23
24 $dbh->do(<<'');
25CREATE TABLE artist (
26 artistid INT IDENTITY NOT NULL,
27 name VARCHAR(255),
28 charfield CHAR(10),
29 primary key(artistid)
30)
31
32my %seen_id;
33
34# test primary key handling
35my $new = $schema->resultset('Artist')->create({ name => 'foo' });
36ok($new->artistid > 0, "Auto-PK worked");
37
38$seen_id{$new->artistid}++;
39
40# test LIMIT support
41for (1..6) {
42 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
43 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
44 $seen_id{$new->artistid}++;
45}
46
47my $it = $schema->resultset('Artist')->search( {}, {
48 rows => 3,
49 order_by => 'artistid',
50});
51
52is( $it->count, 3, "LIMIT count ok" );
53is( $it->next->name, "foo", "iterator->next ok" );
54$it->next;
55is( $it->next->name, "Artist 2", "iterator->next ok" );
56is( $it->next, undef, "next past end of resultset ok" );
57
58
59# clean up our mess
60END {
61 $dbh->do('DROP TABLE artist') if $dbh;
62}
63