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