Segfault
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index 9d46eea..f53d49f 100644 (file)
@@ -10,25 +10,40 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PA
 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(255),
+   name VARCHAR(100),
+   rank INT NOT NULL DEFAULT '13',
    charfield CHAR(10) NULL,
    primary key(artistid)
 )
 
+SQL
+
+});
+
 my %seen_id;
 
 # fresh $schema so we start unconnected
@@ -61,7 +76,7 @@ is( $it->next, undef, "next past end of resultset ok" );
 
 # clean up our mess
 END {
-    $dbh = eval { $schema->storage->_dbh };
+    my $dbh = eval { $schema->storage->_dbh };
     $dbh->do('DROP TABLE artist') if $dbh;
 }