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