);
}
- if ($op eq 'insert' && (not $bound_identity_col) && $identity_col) {
+ if ($op eq 'insert' && (not $bound_identity_col) && $identity_col &&
+ (not $self->{insert_bulk})) {
$sql =
"$sql\n" .
$self->_fetch_identity_sql($ident, $identity_col);
if (not $use_bulk_api) {
my $blob_cols = $self->_remove_blob_cols_array($source, $cols, $data);
- my $dumb_last_insert_id =
- $identity_col
- && (not $is_identity_insert)
- && ($self->_identity_method||'') ne '@@IDENTITY';
+# _execute_array uses a txn anyway, but it ends too early in case we need to
+# select max(col) to get the identity for inserting blobs.
+ ($self, my $guard) = $self->{transaction_depth} == 0 ?
+ ($self->_writer_storage, $self->_writer_storage->txn_scope_guard)
+ :
+ ($self, undef);
- ($self, my ($guard)) = do {
- if ($self->{transaction_depth} == 0 && $blob_cols &&
- $dumb_last_insert_id) {
- ($self->_writer_storage, $self->_writer_storage->txn_scope_guard);
- }
- else {
- ($self, undef);
- }
- };
+ local $self->{insert_bulk} = 1;
$self->next::method(@_);
}
$guard->commit if $guard;
+
return;
}
};
$self->_execute_array(
- $source, $sth, \@bind, \@source_columns, \@new_data, $guard
+ $source, $sth, \@bind, \@source_columns, \@new_data, sub {
+ $guard->commit
+ }
);
$bulk->_query_end($sql);
}
}
+sub _dbh_execute_array {
+ my ($self, $sth, $tuple_status, $cb) = @_;
+
+ my $rv = $self->next::method($sth, $tuple_status);
+ $cb->() if $cb;
+
+ return $rv;
+}
+
# Make sure blobs are not bound as placeholders, and return any non-empty ones
# as a hash.
sub _remove_blob_cols {