Commit | Line | Data |
4ffa5700 |
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 | |
56dca25f |
9 | # Example DSN (from frew): |
10 | # dbi:ADO:PROVIDER=sqlncli10;SERVER=tcp:172.24.2.10;MARS Connection=True;Initial Catalog=CIS;UID=cis_web;PWD=...;DataTypeCompatibility=80; |
11 | |
4ffa5700 |
12 | my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ADO_${_}" } qw/DSN USER PASS/}; |
13 | |
14 | plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ADO_DSN}, _USER and _PASS to run this test' |
15 | unless ($dsn && $user); |
16 | |
4ffa5700 |
17 | my $schema = DBICTest::Schema->connect($dsn, $user, $pass); |
18 | $schema->storage->ensure_connected; |
19 | |
20 | isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server' ); |
21 | |
56dca25f |
22 | my $ver = $schema->storage->_server_info->{normalized_dbms_version}; |
23 | |
24 | ok $ver, 'can introspect DBMS version'; |
25 | |
26 | is $schema->storage->sql_limit_dialect, ($ver >= 9 ? 'RowNumberOver' : 'Top'), |
27 | 'correct limit dialect detected'; |
28 | |
4ffa5700 |
29 | $schema->storage->dbh_do (sub { |
30 | my ($storage, $dbh) = @_; |
56dca25f |
31 | eval { local $^W = 0; $dbh->do("DROP TABLE artist") }; |
4ffa5700 |
32 | $dbh->do(<<'SQL'); |
33 | CREATE TABLE artist ( |
34 | artistid INT IDENTITY NOT NULL, |
35 | name VARCHAR(100), |
36 | rank INT NOT NULL DEFAULT '13', |
37 | charfield CHAR(10) NULL, |
38 | primary key(artistid) |
39 | ) |
40 | SQL |
41 | }); |
42 | |
43 | my $new = $schema->resultset('Artist')->create({ name => 'foo' }); |
44 | ok($new->artistid > 0, 'Auto-PK worked'); |
45 | |
46 | # make sure select works |
47 | my $found = $schema->resultset('Artist')->search({ name => 'foo' })->first; |
48 | is $found->artistid, $new->artistid, 'search works'; |
49 | |
7282bf38 |
50 | # test large column list in select |
51 | $found = $schema->resultset('Artist')->search({ name => 'foo' }, { |
56dca25f |
52 | select => ['artistid', 'name', map \"'foo' foo_$_", 0..50], |
53 | as => ['artistid', 'name', map "foo_$_", 0..50], |
7282bf38 |
54 | })->first; |
55 | is $found->artistid, $new->artistid, 'select with big column list'; |
56 | is $found->get_column('foo_50'), 'foo', 'last item in big column list'; |
e38348dd |
57 | |
4ffa5700 |
58 | # create a few more rows |
8bcd9ece |
59 | for (1..12) { |
4ffa5700 |
60 | $schema->resultset('Artist')->create({ name => 'Artist ' . $_ }); |
61 | } |
62 | |
63 | # test multiple active cursors |
7c5b1b9f |
64 | my $rs1 = $schema->resultset('Artist')->search({}, { order_by => 'artistid' }); |
65 | my $rs2 = $schema->resultset('Artist')->search({}, { order_by => 'name' }); |
4ffa5700 |
66 | |
67 | while ($rs1->next) { |
68 | ok eval { $rs2->next }, 'multiple active cursors'; |
69 | } |
70 | |
8bcd9ece |
71 | # test bug where ADO blows up if the first bindparam is shorter than the second |
72 | is $schema->resultset('Artist')->search({ artistid => 2 })->first->name, |
73 | 'Artist 1', |
74 | 'short bindparam'; |
75 | |
76 | is $schema->resultset('Artist')->search({ artistid => 13 })->first->name, |
77 | 'Artist 12', |
78 | 'longer bindparam'; |
79 | |
80 | done_testing; |
81 | |
4ffa5700 |
82 | # clean up our mess |
83 | END { |
56dca25f |
84 | my $warn_handler = $SIG{__WARN__} || sub { warn @_ }; |
85 | local $SIG{__WARN__} = sub { |
86 | $warn_handler->(@_) unless $_[0] =~ /Not a Win32::OLE object/ |
87 | }; |
4ffa5700 |
88 | if (my $dbh = eval { $schema->storage->_dbh }) { |
89 | eval { $dbh->do("DROP TABLE $_") } |
90 | for qw/artist/; |
91 | } |
92 | } |
93 | # vim:sw=2 sts=2 |