From: Rafael Kitover Date: Tue, 16 Mar 2010 21:01:21 +0000 (+0000) Subject: _ping for MSSQL X-Git-Tag: v0.08121~58 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ecdf1ac8ec414ab62b84c78bad176e125dff553d;hp=6f546d659c5f4207286d0be33f15ce237b9968b9;p=dbsrgits%2FDBIx-Class.git _ping for MSSQL --- diff --git a/lib/DBIx/Class/Storage/DBI/InterBase.pm b/lib/DBIx/Class/Storage/DBI/InterBase.pm index d4e386d..2a789b5 100644 --- a/lib/DBIx/Class/Storage/DBI/InterBase.pm +++ b/lib/DBIx/Class/Storage/DBI/InterBase.pm @@ -206,6 +206,7 @@ sub _ping { my $dbh = $self->_dbh or return 0; local $dbh->{RaiseError} = 1; + local $dbh->{PrintError} = 0; eval { $dbh->do('select 1 from rdb$database'); diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index 6779e86..ce714d4 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -263,6 +263,21 @@ sub sql_maker { return $self->_sql_maker; } +sub _ping { + my $self = shift; + + my $dbh = $self->_dbh or return 0; + + local $dbh->{RaiseError} = 1; + local $dbh->{PrintError} = 0; + + eval { + $dbh->do('select 1'); + }; + + return $@ ? 0 : 1; +} + 1; =head1 NAME diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index a6081a6..955a723 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -110,9 +110,10 @@ sub _ping { my $dbh = $self->_dbh or return 0; local $dbh->{RaiseError} = 1; + local $dbh->{PrintError} = 0; eval { - $dbh->do("select 1 from dual"); + $dbh->do('select 1 from dual'); }; return $@ ? 0 : 1; diff --git a/t/746mssql.t b/t/746mssql.t index ab1bc20..ca92a41 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -33,6 +33,12 @@ isa_ok( $schema->storage, 'DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server ok (! $schema2->storage->connected, 'a re-connected cloned schema starts unconnected'); } +$schema->storage->_dbh->disconnect; + +lives_ok { + $schema->storage->dbh_do(sub { $_[1]->do('select 1') }) +} '_ping works'; + $schema->storage->dbh_do (sub { my ($storage, $dbh) = @_; eval { $dbh->do("DROP TABLE artist") }; diff --git a/t/74mssql.t b/t/74mssql.t index 04efcf6..a882e99 100644 --- a/t/74mssql.t +++ b/t/74mssql.t @@ -52,13 +52,14 @@ for my $storage_type (@storage_types) { isa_ok($schema->storage, "DBIx::Class::Storage::$storage_type"); -# start disconnected to test reconnection +# start disconnected to test _ping $schema->storage->_dbh->disconnect; - my $dbh; - lives_ok (sub { - $dbh = $schema->storage->dbh; - }, 'reconnect works'); + lives_ok { + $schema->storage->dbh_do(sub { $_[1]->do('select 1') }) + } '_ping works'; + + my $dbh = $schema->storage->dbh; $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist");