use List::Util ();
__PACKAGE__->mk_group_accessors('simple' =>
- qw/_identity _blob_log_on_update unsafe_insert/
+ qw/_identity _blob_log_on_update unsafe_insert _insert_dbh/
);
=head1 NAME
my ($self, $type) = @_;
$type = lc $type;
- $type =~ s/ identity//;
+ $type =~ s/\s* identity//x;
return uc($TYPE_MAPPING{$type} || $type);
}
my $blob_cols = $self->_remove_blob_cols($source, $to_insert);
# insert+blob insert done atomically
- my $guard = $self->txn_scope_guard if %$blob_cols;
+ my $guard = $self->txn_scope_guard if $blob_cols;
my $need_last_insert_id = 0;
if (
$need_last_insert_id && !$self->unsafe_insert && !$self->{transaction_depth}
) {
+ $self->_insert_dbh($self->_connect(@{ $self->_dbi_connect_info }))
+ unless $self->_insert_dbh;
+ local $self->{_dbh} = $self->_insert_dbh;
my $guard = $self->txn_scope_guard;
my $upd_cols = $self->next::method (@_);
$guard->commit;
+ $self->_insert_dbh($self->_dbh);
$upd_cols;
}
else {
}
};
- $self->_insert_blobs($source, $blob_cols, $to_insert) if %$blob_cols;
+ $self->_insert_blobs($source, $blob_cols, $to_insert) if $blob_cols;
$guard->commit if $guard;
my $blob_cols = $self->_remove_blob_cols($source, $fields);
# update+blob update(s) done atomically
- my $guard = $self->txn_scope_guard if %$blob_cols;
+ my $guard = $self->txn_scope_guard if $blob_cols;
my @res;
if ($wantarray) {
$self->next::method(@_);
}
- $self->_update_blobs($source, $blob_cols, $where) if %$blob_cols;
+ $self->_update_blobs($source, $blob_cols, $where) if $blob_cols;
- $guard->commit if %$blob_cols;
+ $guard->commit if $guard;
return $wantarray ? @res : $res[0];
}
}
}
- return \%blob_cols;
+ return keys %blob_cols ? \%blob_cols : undef;
}
sub _update_blobs {
L<reset|DBIx::Class::ResultSet/reset>.
Transactions done for inserts in C<AutoCommit> mode when placeholders are in use
-are also affected, so this won't work:
-
- while (my $row = $rs1->next) {
- $rs2->create({ foo => $row->foo });
- }
+are not affected, as they use an extra database handle to do the insert.
Some workarounds:
=over 4
-=item * set C<< $schema->storage->unsafe_insert(1) >> temporarily (see
-L</connect_call_unsafe_insert>)
-
=item * use L<DBIx::Class::Storage::DBI::Replicated>
=item * L<connect|DBIx::Class::Schema/connect> another L<Schema|DBIx::Class::Schema>