From: John Napiorkowski Date: Wed, 10 Jan 2007 21:43:19 +0000 (+0000) Subject: some refactoring to reduce cut and paste work X-Git-Tag: v0.08010~150^2~106^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b64658958ef6dfd9736709f75f206562e262cd8;p=dbsrgits%2FDBIx-Class.git some refactoring to reduce cut and paste work --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 26effd6..cb23efc 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -892,14 +892,8 @@ sub insert { my ($self, $source, $to_insert) = @_; my $ident = $source->from; - my $bind_attributes; - foreach my $column ($source->columns) { - - my $data_type = $source->column_info($column)->{data_type} || ''; - $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type) - if $data_type; - } - + my $bind_attributes = $self->source_bind_attributes($source); + $self->throw_exception( "Couldn't insert ".join(', ', map "$_ => $to_insert->{$_}", keys %$to_insert @@ -956,17 +950,9 @@ sub insert_bulk { #}; ## Get the bind_attributes, if any exist - - my $bind_attributes; - foreach my $column ($source->columns) { - - my $data_type = $source->column_info($column)->{data_type} || ''; - $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type) - if $data_type; - } - + my $bind_attributes = $self->source_bind_attributes($source); + ## Bind the values and execute - $rv = eval { my $placeholder_index = 1; @@ -990,9 +976,6 @@ sub insert_bulk { }; -#print STDERR Dumper($tuple_status); -#print STDERR "RV: $rv\n"; - if ($@ || !defined $rv) { my $errors = ''; foreach my $tuple (@$tuple_status) @@ -1014,16 +997,9 @@ sub insert_bulk { sub update { my $self = shift @_; my $source = shift @_; - - my $bind_attributes; - foreach my $column ($source->columns) { - - my $data_type = $source->column_info($column)->{data_type} || ''; - $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type) - if $data_type; - } - + my $bind_attributes = $self->source_bind_attributes($source); my $ident = $source->from; + return $self->_execute('update' => [], $ident, $bind_attributes, @_); } @@ -1064,6 +1040,20 @@ sub _select { return $self->_execute(@args); } +sub source_bind_attributes { + my ($self, $source) = @_; + + my $bind_attributes; + foreach my $column ($source->columns) { + + my $data_type = $source->column_info($column)->{data_type} || ''; + $bind_attributes->{$column} = $self->bind_attribute_by_data_type($data_type) + if $data_type; + } + + return $bind_attributes; +} + =head2 select =over 4