plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test'
unless ($dsn && $user);
-plan tests => 12;
+plan tests => 13;
my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
-$schema->storage->ensure_connected;
-isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server' );
+{
+ no warnings 'redefine';
+ my $connect_count = 0;
+ my $orig_connect = \&DBI::connect;
+ local *DBI::connect = sub { $connect_count++; goto &$orig_connect };
+
+ $schema->storage->ensure_connected;
+
+ is( $connect_count, 1, 'only one connection made');
+}
-my $dbh = $schema->storage->_dbh;
+isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server' );
-eval { $dbh->do("DROP TABLE artist") };
+$schema->storage->dbh_do (sub {
+ my ($storage, $dbh) = @_;
+ eval { $dbh->do("DROP TABLE artist") };
+ $dbh->do(<<'SQL');
- $dbh->do(<<'');
CREATE TABLE artist (
artistid INT IDENTITY NOT NULL,
name VARCHAR(100),
primary key(artistid)
)
+SQL
+
+});
+
my %seen_id;
# fresh $schema so we start unconnected
# clean up our mess
END {
- $dbh = eval { $schema->storage->_dbh };
+ my $dbh = eval { $schema->storage->_dbh };
$dbh->do('DROP TABLE artist') if $dbh;
}