add TODO test for large column list in select
[dbsrgits/DBIx-Class.git] / t / 747mssql_ado.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Exception;
6 use lib qw(t/lib);
7 use DBICTest;
8
9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/};
10
11 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ADO_DSN}, _USER and _PASS to run this test'
12   unless ($dsn && $user);
13
14 plan tests => 11;
15
16 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
17 $schema->storage->ensure_connected;
18
19 isa_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');
25 CREATE 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 )
32 SQL
33 });
34
35 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
36 ok($new->artistid > 0, 'Auto-PK worked');
37
38 # make sure select works
39 my $found = $schema->resultset('Artist')->search({ name => 'foo' })->first;
40 is $found->artistid, $new->artistid, 'search works';
41
42 # try a select with a big column list
43 TODO: {
44   local $TODO = 'select with a big column list does not work';
45
46   $found = $schema->resultset('Artist')->search({ name => 'foo' }, {
47     select => ['name', map "'foo' foo_$_", 0..50]
48   })->first;
49   is $found->artistid, $new->artistid, 'select with big column list';
50 }
51
52 # create a few more rows
53 for (1..6) {
54   $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
55 }
56
57 # test multiple active cursors
58 my $rs1 = $schema->resultset('Artist')->search({}, { order_by => 'artistid' });
59 my $rs2 = $schema->resultset('Artist')->search({}, { order_by => 'name' });
60
61 while ($rs1->next) {
62   ok eval { $rs2->next }, 'multiple active cursors';
63 }
64
65 # clean up our mess
66 END {
67   if (my $dbh = eval { $schema->storage->_dbh }) {
68     eval { $dbh->do("DROP TABLE $_") }
69       for qw/artist/;
70   }
71 }
72 # vim:sw=2 sts=2