Skip to content

Commit

Permalink
Progress on making prepare_cached work on insert/update/delete statem…
Browse files Browse the repository at this point in the history
…ents and backward compatibility; far from complete
  • Loading branch information
Jared Johnson committed Apr 22, 2009
1 parent b305c90 commit 0c2ffa9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 8 additions & 4 deletions lib/DBIx/Class/Row.pm
Expand Up @@ -19,7 +19,7 @@ BEGIN {
: sub () { 0 };
}

__PACKAGE__->mk_group_accessors('simple' => qw/_source_handle/);
__PACKAGE__->mk_group_accessors('simple' => qw/_source_handle prepare_cached/);

=head1 NAME
Expand Down Expand Up @@ -155,6 +155,10 @@ sub new {
$new->result_source($source);
}

if (my $prepare_cached = delete $attrs->{-prepare_cached}) {
$new->prepare_cached($prepare_cached);
}

if (my $related = delete $attrs->{-from_resultset}) {
@{$new->{_ignore_at_insert}={}}{@$related} = ();
}
Expand Down Expand Up @@ -325,7 +329,7 @@ sub insert {
no warnings 'uninitialized';
warn "MC $self inserting (".join(', ', $self->get_columns).")\n";
};
my $updated_cols = $source->storage->insert($source, { $self->get_columns });
my $updated_cols = $source->storage->insert($source, { $self->get_columns }, $self->prepare_cached);
foreach my $col (keys %$updated_cols) {
$self->store_column($col, $updated_cols->{$col});
}
Expand Down Expand Up @@ -488,7 +492,7 @@ sub update {
my %to_update = $self->get_dirty_columns;
return $self unless keys %to_update;
my $rows = $self->result_source->storage->update(
$self->result_source, \%to_update,
$self->result_source, $self->prepare_cached, \%to_update,
$self->{_orig_ident} || $ident_cond
);
if ($rows == 0) {
Expand Down Expand Up @@ -553,7 +557,7 @@ sub delete {
unless exists $self->{_column_data}{$column};
}
$self->result_source->storage->delete(
$self->result_source, $ident_cond);
$self->result_source, $self->prepare_cached, $ident_cond);
$self->in_storage(undef);
} else {
$self->throw_exception("Can't do class delete without a ResultSource instance")
Expand Down
14 changes: 7 additions & 7 deletions lib/DBIx/Class/Storage/DBI.pm
Expand Up @@ -20,7 +20,7 @@ __PACKAGE__->mk_group_accessors('simple' =>
# the values for these accessors are picked out (and deleted) from
# the attribute hashref passed to connect_info
my @storage_options = qw/
on_connect_do on_disconnect_do prepare_cached unsafe auto_savepoint
on_connect_do on_disconnect_do disable_sth_caching prepare_cached unsafe auto_savepoint
/;
__PACKAGE__->mk_group_accessors('simple' => @storage_options);

Expand Down Expand Up @@ -652,8 +652,6 @@ sub connect_info {

$self->prepare_cached(1); # Default prepare_cached to enabled
if(keys %attrs) {
$attrs{prepare_cached} = ! $attrs{disable_sth_caching}
if exists $attrs{disable_sth_caching};
$self->$_(delete $attrs{$_})
for grep {exists $attrs{$_}} (@storage_options, 'cursor_class'); # @storage_options is declared at the top of the module
$self->_sql_maker_opts->{$_} = delete $attrs{$_}
Expand Down Expand Up @@ -1279,7 +1277,7 @@ sub _execute {
}

sub insert {
my ($self, $source, $to_insert) = @_;
my ($self, $source, $to_insert, $prepare_cached) = @_;

my $ident = $source->from;
my $bind_attributes = $self->source_bind_attributes($source);
Expand All @@ -1295,7 +1293,7 @@ sub insert {
}
}

$self->_execute('insert' => [], $source, $bind_attributes, $self->prepare_cached, $to_insert);
$self->_execute('insert' => [], $source, $bind_attributes, $prepare_cached, $to_insert);

return $to_insert;
}
Expand Down Expand Up @@ -1356,19 +1354,21 @@ sub insert_bulk {
sub update {
my $self = shift @_;
my $source = shift @_;
my $prepare_cached = shift @_;
my $bind_attributes = $self->source_bind_attributes($source);

return $self->_execute('update' => [], $source, $bind_attributes, $self->prepare_cached, @_);
return $self->_execute('update' => [], $source, $bind_attributes, $prepare_cached, @_);
}


sub delete {
my $self = shift @_;
my $source = shift @_;
my $prepare_cached = shift @_;

my $bind_attrs = {}; ## If ever it's needed...

return $self->_execute('delete' => [], $source, $bind_attrs, $self->prepare_cached, @_);
return $self->_execute('delete' => [], $source, $bind_attrs, $prepare_cached, @_);
}

sub _select {
Expand Down

0 comments on commit 0c2ffa9

Please sign in to comment.