use store_column instead of set_column on insert
[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
2eebd801 20my $dbh = $schema->storage->_dbh;
c1cac633 21
22eval { $dbh->do("DROP TABLE artist") };
23
24 $dbh->do(<<'');
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
33my %seen_id;
34
2eebd801 35# fresh $schema so we start unconnected
36$schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
37
c1cac633 38# test primary key handling
39my $new = $schema->resultset('Artist')->create({ name => 'foo' });
40ok($new->artistid > 0, "Auto-PK worked");
41
42$seen_id{$new->artistid}++;
43
44# test LIMIT support
45for (1..6) {
46 $new = $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
47 is ( $seen_id{$new->artistid}, undef, "id for Artist $_ is unique" );
48 $seen_id{$new->artistid}++;
49}
50
51my $it = $schema->resultset('Artist')->search( {}, {
52 rows => 3,
53 order_by => 'artistid',
54});
55
56is( $it->count, 3, "LIMIT count ok" );
57is( $it->next->name, "foo", "iterator->next ok" );
58$it->next;
59is( $it->next->name, "Artist 2", "iterator->next ok" );
60is( $it->next, undef, "next past end of resultset ok" );
61
62
63# clean up our mess
64END {
2eebd801 65 $dbh = eval { $schema->storage->_dbh };
c1cac633 66 $dbh->do('DROP TABLE artist') if $dbh;
67}
68