use DBIx::Class::Storage::DBI::Cursor;
use DBIx::Class::Storage::Statistics;
use IO::File;
-use Carp::Clan qw/DBIx::Class/;
+use Scalar::Util 'blessed';
+
- __PACKAGE__->mk_group_accessors(
- 'simple' =>
- qw/_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid _conn_tid
- disable_sth_caching cursor on_connect_do transaction_depth/
++__PACKAGE__->mk_group_accessors('simple' =>
++ qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts
++ _conn_pid _conn_tid disable_sth_caching cursor on_connect_do
++ transaction_depth/
+);
+
BEGIN {
package DBIC::SQL::Abstract; # Would merge upstream, but nate doesn't reply :(
]
);
+=cut
+
+sub connect_info {
+ my ($self, $info_arg) = @_;
+
+ return $self->_connect_info if !$info_arg;
+
+ # Kill sql_maker/_sql_maker_opts, so we get a fresh one with only
+ # the new set of options
+ $self->_sql_maker(undef);
+ $self->_sql_maker_opts({});
++ $self->_connect_info($info_arg);
+
- my $info = [ @$info_arg ]; # copy because we can alter it
- my $last_info = $info->[-1];
++ my $dbi_info = [@$info_arg]; # copy for DBI
++ my $last_info = $dbi_info->[-1];
+ if(ref $last_info eq 'HASH') {
+ for my $storage_opt (qw/on_connect_do disable_sth_caching/) {
+ if(my $value = delete $last_info->{$storage_opt}) {
+ $self->$storage_opt($value);
+ }
+ }
+ for my $sql_maker_opt (qw/limit_dialect quote_char name_sep/) {
+ if(my $opt_val = delete $last_info->{$sql_maker_opt}) {
+ $self->_sql_maker_opts->{$sql_maker_opt} = $opt_val;
+ }
+ }
+
+ # Get rid of any trailing empty hashref
- pop(@$info) if !keys %$last_info;
++ pop(@$dbi_info) if !keys %$last_info;
+ }
+
- if(ref $info->[0] ne 'CODE') {
++ $self->_dbi_connect_info($dbi_info);
++
++ if(ref $dbi_info->[0] ne 'CODE') {
+ # Extend to 3 arguments with undefs, if necessary
- while(scalar(@$info) < 3) { push(@$info, undef) }
++ while(scalar(@$dbi_info) < 3) { push(@$dbi_info, undef) }
+
+ # Complain if 4th argument is defined and is not a HASH
- if(defined $info->[3] && ref $info->[3] ne 'HASH') {
++ if(defined $dbi_info->[3] && ref $dbi_info->[3] ne 'HASH') {
+ warn "4th argument of DBI connect info is defined "
+ . " but is not a hashref!";
+ }
+
+ # Set AutoCommit to 1 if not specified manually
+ else {
- $info->[3] ||= {};
- if(!defined $info->[3]->{AutoCommit}) {
- $info->[3]->{AutoCommit} = 1;
++ $dbi_info->[3] ||= {};
++ if(!defined $dbi_info->[3]->{AutoCommit}) {
++ $dbi_info->[3]->{AutoCommit} = 1;
+ }
+ }
+ }
+
- $self->_connect_info($info);
++ $self->_connect_info;
+}
+
=head2 on_connect_do
This method is deprecated in favor of setting via L</connect_info>.
return $self->_sql_maker;
}
-sub connect_info {
- my ($self, $info_arg) = @_;
-
- if($info_arg) {
- # Kill sql_maker/_sql_maker_opts, so we get a fresh one with only
- # the new set of options
- $self->_sql_maker(undef);
- $self->_sql_maker_opts({});
- $self->_connect_info($info_arg);
-
- my $dbi_info = [@$info_arg]; # copy for DBI
- my $last_info = $dbi_info->[-1];
- if(ref $last_info eq 'HASH') {
- if(my $on_connect_do = delete $last_info->{on_connect_do}) {
- $self->on_connect_do($on_connect_do);
- }
- for my $sql_maker_opt (qw/limit_dialect quote_char name_sep/) {
- if(my $opt_val = delete $last_info->{$sql_maker_opt}) {
- $self->_sql_maker_opts->{$sql_maker_opt} = $opt_val;
- }
- }
-
- # Get rid of any trailing empty hashref
- pop(@$dbi_info) if !keys %$last_info;
- }
-
- $self->_dbi_connect_info($dbi_info);
- }
-
- $self->_connect_info;
-}
-
sub _populate_dbh {
my ($self) = @_;
- my @info = @{$self->_connect_info || []};
+ my @info = @{$self->_dbi_connect_info || []};
$self->_dbh($self->_connect(@info));
+ # Always set the transaction depth on connect, since
+ # there is no transaction in progress by definition
+ $self->{transaction_depth} = $self->_dbh->{AutoCommit} ? 0 : 1;
+
if(ref $self eq 'DBIx::Class::Storage::DBI') {
my $driver = $self->_dbh->{Driver}->{Name};
if ($self->load_optional_class("DBIx::Class::Storage::DBI::${driver}")) {