From: Rafael Kitover Date: Tue, 29 Sep 2009 02:25:55 +0000 (+0000) Subject: removed some dead code, added fix and test for _execute_array_empty X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=574d7df6e52ed1bdb9278acfd0960910929c6078;p=dbsrgits%2FDBIx-Class-Historic.git removed some dead code, added fix and test for _execute_array_empty --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index d5dc47c..a9e0191 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1796,7 +1796,10 @@ sub populate { } else { my ($first, @rest) = @$data; - my @names = grep {!ref $first->{$_}} keys %$first; + my @names = grep { + (not ref $first->{$_}) || (ref $first->{$_} eq 'SCALAR') + } keys %$first; + my @rels = grep { $self->result_source->has_relationship($_) } keys %$first; my @pks = $self->result_source->primary_columns; @@ -2796,10 +2799,7 @@ sub _resolved_attrs { : ( ( delete $attrs->{columns} ) || - $source->storage->order_select_columns( - $source, - [ $source->columns ], - ) + $source->columns ) ; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index eac1dda..cdef7eb 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1335,7 +1335,7 @@ sub insert { ## scalar refs, or at least, all the same type as the first set, the statement is ## only prepped once. sub insert_bulk { - my ($self, $source, $cols, $data, $sth_attr) = @_; + my ($self, $source, $cols, $data) = @_; # redispatch to insert_bulk method of storage we reblessed into, if necessary if (not $self->_driver_determined) { @@ -1374,7 +1374,7 @@ sub insert_bulk { } $self->_query_start( $sql, @bind ); - my $sth = $self->sth($sql, 'insert', $sth_attr); + my $sth = $self->sth($sql); my $rv = do { if ($empty_bind) { @@ -2053,27 +2053,6 @@ sub _subq_count_select { return @pcols ? \@pcols : [ 1 ]; } -=head2 order_select_columns - -=over 4 - -=item Arguments: $source, \@columns - -=back - -Returns an ordered list of column names to be used in a SELECT statement. By -default simply returns the list that was passed in. - -This may be overridden in a specific storage when there are requirements such as -moving BLOB columns to the end of the SELECT list. - -=cut - -sub order_select_columns { - #my ($self, $source, $columns) = @_; - return @{$_[2]}; -} - sub source_bind_attributes { my ($self, $source) = @_; @@ -2132,15 +2111,12 @@ Returns a L sth (statement handle) for the supplied SQL. =cut sub _dbh_sth { - my ($self, $dbh, $sql, $op, $sth_attr) = @_; -# $op is ignored right now - - $sth_attr ||= {}; + my ($self, $dbh, $sql) = @_; # 3 is the if_active parameter which avoids active sth re-use my $sth = $self->disable_sth_caching - ? $dbh->prepare($sql, $sth_attr) - : $dbh->prepare_cached($sql, $sth_attr, 3); + ? $dbh->prepare($sql) + : $dbh->prepare_cached($sql, {}, 3); # XXX You would think RaiseError would make this impossible, # but apparently that's not true :( @@ -2150,8 +2126,8 @@ sub _dbh_sth { } sub sth { - my ($self, $sql, $op, $sth_attr) = @_; - $self->dbh_do('_dbh_sth', $sql, $op, $sth_attr); # retry over disconnects + my ($self, $sql) = @_; + $self->dbh_do('_dbh_sth', $sql); # retry over disconnects } sub _dbh_columns_info_for { diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 759f3ac..1589b5f 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -325,7 +325,6 @@ has 'write_handler' => ( _count_select _subq_count_select _subq_update_delete - order_select_columns svp_rollback svp_begin svp_release diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index f82a3c5..ed9c6e0 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -449,6 +449,8 @@ sub update { # it is originally put by _remove_blob_cols .) my %blobs_to_empty = map { ($_ => delete $fields->{$_}) } keys %$blob_cols; +# We can't only update NULL blobs, because blobs cannot be in the WHERE clause. + $self->next::method($source, \%blobs_to_empty, $where, @rest); # Now update the blobs before the other columns in case the update of other diff --git a/t/100populate.t b/t/100populate.t index ec765aa..abd70c8 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -6,7 +6,7 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; -plan tests => 23; +plan tests => 24; my $schema = DBICTest->init_schema(); @@ -116,3 +116,19 @@ is($link7->id, 7, 'Link 7 id'); is($link7->url, undef, 'Link 7 url'); is($link7->title, 'gtitle', 'Link 7 title'); +# test _execute_array_empty (insert_bulk with all literal sql) +my $rs = $schema->resultset('Artist'); +$rs->delete; +$rs->populate([ + (+{ + name => \"'DT'", + rank => \500, + charfield => \"'mtfnpy'", + }) x 5 +]); + +is((grep { + $_->name eq 'DT' && + $_->rank == 500 && + $_->charfield eq 'mtfnpy' +} $rs->all), 5, 'populate with all literal SQL');