From: Peter Rabbitson Date: Thu, 28 Jan 2010 10:13:16 +0000 (+0000) Subject: Consolidate insert_bulk guards (and make them show up correctly in the trace) X-Git-Tag: v0.08116~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b0e64d8f6a86fdfe9290bb1ea8672b1e54a5319;p=dbsrgits%2FDBIx-Class.git Consolidate insert_bulk guards (and make them show up correctly in the trace) --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index ac4161d..e07f116 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1468,9 +1468,13 @@ sub insert_bulk { ); } + # neither _execute_array, nor _execute_inserts_with_no_binds are + # atomic (even if _execute _array is a single call). Thus a safety + # scope guard + my $guard = $self->txn_scope_guard unless $self->{transaction_depth} != 0; + $self->_query_start( $sql, ['__BULK__'] ); my $sth = $self->sth($sql); - my $rv = do { if ($empty_bind) { # bind_param_array doesn't work if there are no binds @@ -1484,14 +1488,15 @@ sub insert_bulk { $self->_query_end( $sql, ['__BULK__'] ); + + $guard->commit if $guard; + return (wantarray ? ($rv, $sth, @bind) : $rv); } sub _execute_array { my ($self, $source, $sth, $bind, $cols, $data, @extra) = @_; - my $guard = $self->txn_scope_guard unless $self->{transaction_depth} != 0; - ## This must be an arrayref, else nothing works! my $tuple_status = []; @@ -1540,9 +1545,6 @@ sub _execute_array { }), ); } - - $guard->commit if $guard; - return $rv; } @@ -1555,8 +1557,6 @@ sub _dbh_execute_array { sub _dbh_execute_inserts_with_no_binds { my ($self, $sth, $count) = @_; - my $guard = $self->txn_scope_guard unless $self->{transaction_depth} != 0; - eval { my $dbh = $self->_get_dbh; local $dbh->{RaiseError} = 1; @@ -1572,8 +1572,6 @@ sub _dbh_execute_inserts_with_no_binds { $self->throw_exception($exception) if $exception; - $guard->commit if $guard; - return $count; }