fix the large column list test for ADO/MSSQL, now passes
[dbsrgits/DBIx-Class.git] / t / 747mssql_ado.t
CommitLineData
4ffa5700 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8
9my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
10
11plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ADO_DSN}, _USER and _PASS to run this test'
12 unless ($dsn && $user);
13
7282bf38 14plan tests => 12;
4ffa5700 15
16my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
17$schema->storage->ensure_connected;
18
19isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server' );
20
21$schema->storage->dbh_do (sub {
22 my ($storage, $dbh) = @_;
23 eval { $dbh->do("DROP TABLE artist") };
24 $dbh->do(<<'SQL');
25CREATE TABLE artist (
26 artistid INT IDENTITY NOT NULL,
27 name VARCHAR(100),
28 rank INT NOT NULL DEFAULT '13',
29 charfield CHAR(10) NULL,
30 primary key(artistid)
31)
32SQL
33});
34
35my $new = $schema->resultset('Artist')->create({ name => 'foo' });
36ok($new->artistid > 0, 'Auto-PK worked');
37
38# make sure select works
39my $found = $schema->resultset('Artist')->search({ name => 'foo' })->first;
40is $found->artistid, $new->artistid, 'search works';
41
7282bf38 42# test large column list in select
43$found = $schema->resultset('Artist')->search({ name => 'foo' }, {
44 select => ['artistid', 'name', map "'foo' foo_$_", 0..50],
45 as => ['artistid', 'name', map "foo_$_", 0..50],
46})->first;
47is $found->artistid, $new->artistid, 'select with big column list';
48is $found->get_column('foo_50'), 'foo', 'last item in big column list';
e38348dd 49
4ffa5700 50# create a few more rows
51for (1..6) {
52 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
53}
54
55# test multiple active cursors
7c5b1b9f 56my $rs1 = $schema->resultset('Artist')->search({}, { order_by => 'artistid' });
57my $rs2 = $schema->resultset('Artist')->search({}, { order_by => 'name' });
4ffa5700 58
59while ($rs1->next) {
60 ok eval { $rs2->next }, 'multiple active cursors';
61}
62
63# clean up our mess
64END {
65 if (my $dbh = eval { $schema->storage->_dbh }) {
66 eval { $dbh->do("DROP TABLE $_") }
67 for qw/artist/;
68 }
69}
70# vim:sw=2 sts=2