X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=355edf942b762ac17004e798810f20ed6384a177;hb=90a63099ad8b0269a300f6aa1c48d336e9e6c21e;hp=094b508e978380ab10b9c4451dddc8ae9d7731e9;hpb=28be49a61823d8e7592ddd9c81e86066fd47e6ee;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 094b508..355edf9 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -530,15 +530,8 @@ sub dbh_do { local $self->{_in_dbh_do} = 1; - $self->_do_with_reconnect($code, @_); -} - -sub _do_with_reconnect { - my $self = shift; - my $code = shift; my @result; my $want_array = wantarray; - my $dbh = $self->_dbh; eval { $self->_verify_pid if $dbh; @@ -608,7 +601,7 @@ sub txn_do { my $exception = $@; if(!$exception) { return $want_array ? @result : $result[0] } - if($tried++ > 0 || $self->connected) { + if($tried++ || $self->connected) { eval { $self->txn_rollback }; my $rollback_exception = $@; if($rollback_exception) { @@ -648,7 +641,8 @@ sub disconnect { $self->_do_connection_actions(disconnect_call_ => $_) for @actions; - $self->_dbh->rollback unless $self->_dbh_autocommit; + $self->_dbh_rollback unless $self->_dbh_autocommit; + $self->_dbh->disconnect; $self->_dbh(undef); $self->{_dbh_gen}++; @@ -1060,23 +1054,31 @@ sub txn_begin { if($self->{transaction_depth} == 0) { $self->debugobj->txn_begin() if $self->debug; - # this isn't ->_dbh-> because - # we should reconnect on begin_work - # for AutoCommit users - $self->_do_with_reconnect(sub { $_[1]->begin_work }); - } elsif ($self->auto_savepoint) { + $self->_dbh_begin_work; + } + elsif ($self->auto_savepoint) { $self->svp_begin; } $self->{transaction_depth}++; } +sub _dbh_begin_work { + my $self = shift; + # being here implies we have AutoCommit => 1 + # if the user is utilizing txn_do - good for + # him, otherwise we need to ensure that the + # $dbh is healthy on BEGIN + my $dbh_method = $self->{_in_dbh_do} ? '_dbh' : 'dbh'; + $self->$dbh_method->begin_work; +} + sub txn_commit { my $self = shift; if ($self->{transaction_depth} == 1) { my $dbh = $self->_dbh; $self->debugobj->txn_commit() if ($self->debug); - $dbh->commit; + $self->_dbh_commit; $self->{transaction_depth} = 0 if $self->_dbh_autocommit; } @@ -1087,6 +1089,11 @@ sub txn_commit { } } +sub _dbh_commit { + my $self = shift; + $self->_dbh->commit; +} + sub txn_rollback { my $self = shift; my $dbh = $self->_dbh; @@ -1096,7 +1103,7 @@ sub txn_rollback { if ($self->debug); $self->{transaction_depth} = 0 if $self->_dbh_autocommit; - $dbh->rollback; + $self->_dbh_rollback; } elsif($self->{transaction_depth} > 1) { $self->{transaction_depth}--; @@ -1119,6 +1126,11 @@ sub txn_rollback { } } +sub _dbh_rollback { + my $self = shift; + $self->_dbh->rollback; +} + # This used to be the top-half of _execute. It was split out to make it # easier to override in NoBindVars without duping the rest. It takes up # all of _execute's args, and emits $sql, @bind. @@ -1856,6 +1868,21 @@ sub _subq_count_select { return @pcols ? \@pcols : [ 1 ]; } +# +# Returns an ordered list of column names before they are used +# in a SELECT statement. By default simply returns the list +# passed in. +# +# This may be overridden in a specific storage when there are +# requirements such as moving BLOB columns to the end of the +# SELECT list. +sub _order_select_columns { + #my ($self, $source, $columns) = @_; + return @{$_[2]}; +} + + + sub source_bind_attributes { my ($self, $source) = @_;