Better diagnostics in the case of missing drivers, slight ADO/ODBC refactor
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ADO.pm
CommitLineData
56dca25f 1package DBIx::Class::Storage::DBI::ADO;
4ffa5700 2
3use base 'DBIx::Class::Storage::DBI';
56dca25f 4use mro 'c3';
4ffa5700 5
772a1a25 6use Sub::Name;
8892d8e5 7use Try::Tiny;
772a1a25 8use namespace::clean;
9
56dca25f 10=head1 NAME
11
12DBIx::Class::Storage::DBI::ADO - Support for L<DBD::ADO>
13
14=head1 DESCRIPTION
15
16This class provides a mechanism for discovering and loading a sub-class
17for a specific ADO backend, as well as some workarounds for L<DBD::ADO>. It
18should be transparent to the user.
19
20=cut
21
75d3bdb2 22sub _rebless { shift->_determine_connector_driver('ADO') }
56dca25f 23
24# cleanup some warnings from DBD::ADO
25# RT#65563, not fixed as of DBD::ADO v2.98
26sub _dbh_get_info {
27 my $self = shift;
28
29 my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
30
31 local $SIG{__WARN__} = sub {
32 $warn_handler->(@_)
33 unless $_[0] =~ m{^Missing argument in sprintf at \S+/ADO/GetInfo\.pm};
52b420dd 34 };
56dca25f 35
36 $self->next::method(@_);
4ffa5700 37}
38
772a1a25 39# Monkeypatch out the horrible warnings during global destruction.
8892d8e5 40# A patch to DBD::ADO has been submitted as well, and it was fixed
41# as of 2.99
772a1a25 42# https://rt.cpan.org/Ticket/Display.html?id=65563
43sub _init {
8892d8e5 44 unless ($DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__) {
45 require DBD::ADO;
46
47 unless (try { DBD::ADO->VERSION('2.99'); 1 }) {
48 no warnings 'redefine';
49 my $disconnect = *DBD::ADO::db::disconnect{CODE};
50
51 *DBD::ADO::db::disconnect = subname 'DBD::ADO::db::disconnect' => sub {
52 my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
53 local $SIG{__WARN__} = sub {
54 $warn_handler->(@_)
55 unless $_[0] =~ /Not a Win32::OLE object|uninitialized value/;
56 };
57 $disconnect->(@_);
772a1a25 58 };
8892d8e5 59 }
60
61 $DBD::ADO::__DBIC_MONKEYPATCH_CHECKED__ = 1;
772a1a25 62 }
63}
64
748eb620 65# Here I was just experimenting with ADO cursor types, left in as a comment in
66# case you want to as well. See the DBD::ADO docs.
4ffa5700 67#sub _dbh_sth {
68# my ($self, $dbh, $sql) = @_;
69#
70# my $sth = $self->disable_sth_caching
71# ? $dbh->prepare($sql, { CursorType => 'adOpenStatic' })
72# : $dbh->prepare_cached($sql, { CursorType => 'adOpenStatic' }, 3);
73#
74# $self->throw_exception($dbh->errstr) if !$sth;
75#
76# $sth;
77#}
78
791;
56dca25f 80
81=head1 AUTHOR
82
83See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
84
85=head1 LICENSE
86
87You may distribute this code under the same terms as Perl itself.
88
89=cut
90# vim:sts=2 sw=2: