X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FADO.pm;h=98c1941defd5b2162d8b43c7ea6cee97f2b89a27;hb=9c1700e39e6ee002d9294c0d988882d1f0d7d86f;hp=8a0fa6848382a1ffcc770e735f0738270906fa25;hpb=4ffa57005fd6e9ecadbfc11157686e8d770e0df6;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/ADO.pm b/lib/DBIx/Class/Storage/DBI/ADO.pm index 8a0fa68..98c1941 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO.pm @@ -1,32 +1,85 @@ -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 Sub::Name; +use namespace::clean; + +=head1 NAME + +DBIx::Class::Storage::DBI::ADO - Support for L + +=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. 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 - my $dbtype = eval { - @{$self->_get_dbh - ->selectrow_arrayref(qq{sp_server_info \@attribute_id=1}) - }[2] + my $dbtype = $self->_dbh_get_info(17); + + if (not $dbtype) { + warn "Unable to determine ADO driver, failling back to generic support.\n"; + 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; + } + else { + warn "Expected driver '$subclass' not found, using generic support. " . + "Please file an RT.\n"; + } +} + +# 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}; }; - unless ($@) { - $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; - } + $self->next::method(@_); +} + +# Monkeypatch out the horrible warnings during global destruction. +# A patch to DBD::ADO has been submitted as well. +# https://rt.cpan.org/Ticket/Display.html?id=65563 +sub _init { + no warnings 'redefine'; + require DBD::ADO; + + if ($DBD::ADO::VERSION <= 2.98) { + my $disconnect = *DBD::ADO::db::disconnect{CODE}; + + *DBD::ADO::db::disconnect = subname 'DBD::ADO::db::disconnect' => sub { + my $warn_handler = $SIG{__WARN__} || sub { warn @_ }; + local $SIG{__WARN__} = sub { + $warn_handler->(@_) + unless $_[0] =~ /Not a Win32::OLE object|uninitialized value/; + }; + $disconnect->(@_); + }; } } -# set cursor type here, if necessary +# Here I was just experimenting with ADO cursor types, left in as a comment in +# case you want to as well. See the DBD::ADO docs. #sub _dbh_sth { # my ($self, $dbh, $sql) = @_; # @@ -40,3 +93,14 @@ sub _rebless { #} 1; + +=head1 AUTHOR + +See L and L. + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut +# vim:sts=2 sw=2: