Cleanup exception handling
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / Common.pm
index c183a9f..af4c916 100644 (file)
@@ -28,7 +28,17 @@ sub _ping {
   my $dbh = $self->_dbh or return 0;
 
   local $dbh->{RaiseError} = 1;
+  local $dbh->{PrintError} = 0;
+
+  if ($dbh->{syb_no_child_con}) {
+# ping is impossible with an active statement, we return false if so
+    my $ping = eval { $dbh->ping };
+    return $@ ? 0 : $ping;
+  }
+
   eval {
+# XXX if the main connection goes stale, does opening another for this statement
+# really determine anything?
     $dbh->do('select 1');
   };
 
@@ -61,7 +71,7 @@ the Sybase OpenClient libraries were used.
 sub using_freetds {
   my $self = shift;
 
-  return $self->_dbh->{syb_oc_version} =~ /freetds/i;
+  return $self->_get_dbh->{syb_oc_version} =~ /freetds/i;
 }
 
 =head2 set_textsize
@@ -72,14 +82,16 @@ use this function instead. It does:
   $dbh->do("SET TEXTSIZE $bytes");
 
 Takes the number of bytes, or uses the C<LongReadLen> value from your
-L<DBIx::Class/connect_info> if omitted.
+L<DBIx::Class/connect_info> if omitted, lastly falls back to the C<32768> which
+is the L<DBD::Sybase> default.
 
 =cut
 
 sub set_textsize {
   my $self = shift;
   my $text_size = shift ||
-    eval { $self->_dbi_connect_info->[-1]->{LongReadLen} };
+    eval { $self->_dbi_connect_info->[-1]->{LongReadLen} } ||
+    32768; # the DBD::Sybase default
 
   return unless defined $text_size;