Remove small_datetime from the main schema - it is not a standard datatype
[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 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
15 $schema->storage->ensure_connected;
16
17 isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server' );
18
19 $schema->storage->dbh_do (sub {
20     my ($storage, $dbh) = @_;
21     eval { $dbh->do("DROP TABLE artist") };
22     $dbh->do(<<'SQL');
23 CREATE TABLE artist (
24    artistid INT IDENTITY NOT NULL,
25    name VARCHAR(100),
26    rank INT NOT NULL DEFAULT '13',
27    charfield CHAR(10) NULL,
28    primary key(artistid)
29 )
30 SQL
31 });
32
33 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
34 ok($new->artistid > 0, 'Auto-PK worked');
35
36 # make sure select works
37 my $found = $schema->resultset('Artist')->search({ name => 'foo' })->first;
38 is $found->artistid, $new->artistid, 'search works';
39
40 # test large column list in select
41 $found = $schema->resultset('Artist')->search({ name => 'foo' }, {
42   select => ['artistid', 'name', map "'foo' foo_$_", 0..50],
43   as     => ['artistid', 'name', map       "foo_$_", 0..50],
44 })->first;
45 is $found->artistid, $new->artistid, 'select with big column list';
46 is $found->get_column('foo_50'), 'foo', 'last item in big column list';
47
48 # create a few more rows
49 for (1..12) {
50   $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
51 }
52
53 # test multiple active cursors
54 my $rs1 = $schema->resultset('Artist')->search({}, { order_by => 'artistid' });
55 my $rs2 = $schema->resultset('Artist')->search({}, { order_by => 'name' });
56
57 while ($rs1->next) {
58   ok eval { $rs2->next }, 'multiple active cursors';
59 }
60
61 # test bug where ADO blows up if the first bindparam is shorter than the second
62 is $schema->resultset('Artist')->search({ artistid => 2 })->first->name,
63   'Artist 1',
64   'short bindparam';
65
66 is $schema->resultset('Artist')->search({ artistid => 13 })->first->name,
67   'Artist 12',
68   'longer bindparam';
69
70 done_testing;
71
72 # clean up our mess
73 END {
74   if (my $dbh = eval { $schema->storage->_dbh }) {
75     eval { $dbh->do("DROP TABLE $_") }
76       for qw/artist/;
77   }
78 }
79 # vim:sw=2 sts=2