Multiple code/test/doc improvements for MSSQL over DBD::ADO
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO.pm
index aa9fb5d..91d731c 100644 (file)
@@ -1,29 +1,53 @@
-package # hide from PAUSE
-    DBIx::Class::Storage::DBI::ADO;
+package DBIx::Class::Storage::DBI::ADO;
 
 use base 'DBIx::Class::Storage::DBI';
+use mro 'c3';
 use Try::Tiny;
 use namespace::clean;
 
+=head1 NAME
+
+DBIx::Class::Storage::DBI::ADO - Support for L<DBD::ADO>
+
+=head1 DESCRIPTION
+
+This class provides a mechanism for discovering and loading a sub-class
+for a specific ADO backend, as well as some workarounds for L<DBD::ADO>. It
+should be transparent to the user.
+
+=cut
+
 sub _rebless {
   my $self = shift;
 
-# check for MSSQL
-# XXX This should be using an OpenSchema method of some sort, but I don't know
-# how.
-# Current version is stolen from Sybase.pm
-  try {
-    my $dbtype = @{$self->_get_dbh
-      ->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})
-    }[2];
-
-    $dbtype =~ s/\W/_/gi;
-    my $subclass = "DBIx::Class::Storage::DBI::ADO::${dbtype}";
-    if ($self->load_optional_class($subclass) && !$self->isa($subclass)) {
-      bless $self, $subclass;
-      $self->_rebless;
-    }
+  my $dbtype = $self->_dbh_get_info(17);
+
+  if (not $dbtype) {
+    warn 'Unable to determine ADO driver, failling back to generic support';
+    return;
+  }
+
+  $dbtype =~ s/\W/_/gi;
+  my $subclass = "DBIx::Class::Storage::DBI::ADO::${dbtype}";
+  if ($self->load_optional_class($subclass) && !$self->isa($subclass)) {
+    bless $self, $subclass;
+    $self->_rebless;
+  }
+}
+
+# cleanup some warnings from DBD::ADO
+# RT#65563, not fixed as of DBD::ADO v2.98
+sub _dbh_get_info {
+  my $self = shift;
+
+  my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
+
+  local $SIG{__WARN__} = sub {
+    $warn_handler->(@_)
+      unless $_[0] =~ m{^Missing argument in sprintf at \S+/ADO/GetInfo\.pm};
   };
+
+  $self->next::method(@_);
 }
 
 # Here I was just experimenting with ADO cursor types, left in as a comment in
@@ -41,3 +65,14 @@ sub _rebless {
 #}
 
 1;
+
+=head1 AUTHOR
+
+See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
+# vim:sts=2 sw=2: