my ($self) = @_;
my @info = @{$self->_connect_info || []};
$self->_dbh($self->_connect(@info));
- my $dbh = $self->_dbh;
- my $driver = $dbh->{Driver}->{Name};
- if ( $driver eq 'ODBC' and $dbh->get_info(17) =~ m{^DB2/400} ) {
- $driver = 'ODBC400';
- }
+ my $driver = $self->_dbh->{Driver}->{Name};
eval "require DBIx::Class::Storage::DBI::${driver}";
unless ($@) {
bless $self, "DBIx::Class::Storage::DBI::${driver}";
+ $self->_rebless() if $self->can('_rebless');
}
# if on-connect sql statements are given execute them
foreach my $sql_statement (@{$self->on_connect_do || []}) {
--- /dev/null
+package DBIx::Class::Storage::DBI::ODBC;
+use strict;
+use warnings;
+
+use base qw/DBIx::Class::Storage::DBI/;
+
+sub _rebless {
+ my ($self) = @_;
+
+ my $dbh = $self->_dbh;
+ my $dbtype = eval { $dbh->get_info(17) };
+ unless ( $@ ) {
+ # Translate the backend name into a perl identifier
+ $dbtype =~ s/\W/_/gi;
+ my $class = "DBIx::Class::Storage::DBI::ODBC::${dbtype}";
+ eval "require $class";
+ bless $self, $class unless $@;
+ }
+}
+
+
+1;
+
+=head1 NAME
+
+DBIx::Class::Storage::DBI::ODBC - Base class for ODBC drivers
+
+=head1 SYNOPSIS
+
+ # In your table classes
+ __PACKAGE__->load_components(qw/Core/);
+
+
+=head1 DESCRIPTION
+
+This class simply provides a mechanism for discovering and loading a sub-class
+for a specific ODBC backend. It should be transparent to the user.
+
+
+=head1 AUTHORS
+
+Marc Mims C<< <marc@sssonline.com> >>
+
+=head1 LICENSE
+
+You may distribute this code under the same terms as Perl itself.
+
+=cut
-package DBIx::Class::Storage::DBI::ODBC400;
+package DBIx::Class::Storage::DBI::ODBC::DB2_400_SQL;
use strict;
use warnings;
-use base qw/DBIx::Class::Storage::DBI/;
+use base qw/DBIx::Class::Storage::DBI::ODBC/;
sub last_insert_id
{
=head1 NAME
-DBIx::Class::Storage::DBI::ODBC400 - Automatic primary key class for DB2/400
+DBIx::Class::Storage::DBI::ODBC::DB2_400_SQL - Automatic primary key class for DB2/400
over ODBC
=head1 SYNOPSIS
=head1 AUTHORS
-Marc Mims C<< <marc@questright.com> >>
+Marc Mims C<< <marc@sssonline.com> >>
Based on DBIx::Class::Storage::DBI::DB2 by Jess Robinson.