From: Matt Phillips Date: Fri, 3 May 2013 21:56:33 +0000 (-0400) Subject: squash, continued fiddling X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b39ea8c17ef98eee6078a7e8b3bf9bd2e7e700c;p=dbsrgits%2FDBIx-Class.git squash, continued fiddling --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 2d415e3..a5085cd 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1961,10 +1961,28 @@ sub insert { return { %$prefetched_values, %returned_cols }; } +# $data is an array of one or many of +# - [[col1, col2], [col1, col2]], +# \['(SELECT...)' +# [ { bind..}, val] ] + sub insert_bulk { my ($self, $source, $cols, $data) = @_; - my $reference_row = ref $data eq 'CODE' ? $data->() : shift @$data; + my $reference_row = do { + if (ref $data eq 'CODE') { + $data->(); + } + elsif (ref $data eq 'ARRAY') { + shift @$data; + } + elsif (ref $data eq 'REF' && ref $$data eq 'ARRAY') { + $data; + } + else { + $self->throw_exception('invalid data (not CODE, ARRAY or ARRAYREF) passed to insert_bulk'); + } + }; my @col_range = (0..$#$cols); @@ -2000,9 +2018,12 @@ sub insert_bulk { my ($proto_data, $value_type_by_col_idx); for my $i (@col_range) { my $colname = $cols->[$i]; - if (ref $reference_row->[$i] eq 'SCALAR') { + if (ref $reference_row eq 'REF' && ref $$reference_row eq 'ARRAY') { + $proto_data = $reference_row; + last; + } + elsif (ref $reference_row eq 'ARRAY' && ref $reference_row->[$i] eq 'SCALAR') { # no bind value at all - no type - $proto_data->{$colname} = $reference_row->[$i]; } elsif (ref $reference_row->[$i] eq 'REF' and ref ${$reference_row->[$i]} eq 'ARRAY' ) { @@ -2043,6 +2064,8 @@ sub insert_bulk { [ $proto_data ], ); + use DDP; p $proto_data; + if (! @$proto_bind and keys %$value_type_by_col_idx) { # if the bindlist is empty and we had some dynamic binds, this means the # storage ate them away (e.g. the NoBindVars component) and interpolated diff --git a/t/100populate.t b/t/100populate.t index fad5575..d0ac5a5 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -446,3 +446,16 @@ lives_ok ( sub { }, 'empty has_many relationship accepted by populate'); done_testing; + +use DDP; use Data::Dumper; +my $q = $schema->resultset('Artist') + ->search({ + artist => { '<' => $schema->resultset('Artist')->search->get_column('id')->max_rs->as_query }, + name => 'foo' + })->as_query; + use DDP; p $q; +#p $q; +#diag Dumper($q); +#p $schema->resultset('Artist')->result_source; +#p Dumper $q; +$schema->storage->insert_bulk($schema->resultset('Artist')->result_source, [qw/artistid name/], $q);