Better diagnostics in the case of missing drivers, slight ADO/ODBC refactor
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ODBC.pm
1 package DBIx::Class::Storage::DBI::ODBC;
2 use strict;
3 use warnings;
4 use base qw/DBIx::Class::Storage::DBI/;
5 use mro 'c3';
6
7 sub _rebless { shift->_determine_connector_driver('ODBC') }
8
9 # Whether or not we are connecting via the freetds ODBC driver
10 sub _using_freetds {
11   my $self = shift;
12
13   my $dsn = $self->_dbi_connect_info->[0];
14
15   return 1 if (
16     ( (! ref $dsn) and $dsn =~ /driver=FreeTDS/i)
17       or
18     ( ($self->_dbh_get_info('SQL_DRIVER_NAME')||'') =~ /tdsodbc/i )
19   );
20
21   return 0;
22 }
23
24 # Either returns the FreeTDS version via which we are connecting, 0 if can't
25 # be determined, or undef otherwise
26 sub _using_freetds_version {
27   my $self = shift;
28   return undef unless $self->_using_freetds;
29   return $self->_dbh_get_info('SQL_DRIVER_VER') || 0;
30 }
31
32 sub _disable_odbc_array_ops {
33   my $self = shift;
34   my $dbh  = $self->_get_dbh;
35
36   if (eval { DBD::ODBC->VERSION('1.35_01') }) {
37     $dbh->{odbc_array_operations} = 0;
38   }
39   elsif (eval { DBD::ODBC->VERSION('1.33_01') }) {
40     $dbh->{odbc_disable_array_operations} = 1;
41   }
42 }
43
44 1;
45
46 =head1 NAME
47
48 DBIx::Class::Storage::DBI::ODBC - Base class for ODBC drivers
49
50 =head1 DESCRIPTION
51
52 This class simply provides a mechanism for discovering and loading a sub-class
53 for a specific ODBC backend.  It should be transparent to the user.
54
55 =head1 AUTHOR
56
57 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
58
59 =head1 LICENSE
60
61 You may distribute this code under the same terms as Perl itself.
62
63 =cut
64 # vim:sts=2 sw=2: