X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=63997aa5d1af2f0bdf537af1e50619ed4e53b9f5;hb=6636ad53c7480e9546c2a0a3ecaa5a807874c819;hp=0b4c4b73b1d1a36a7c8778cea96ca5c3d0101538;hpb=4913997492ff5a1db89762fc4713512e0ffc142e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 0b4c4b7..63997aa 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -927,6 +927,22 @@ sub _fix_bind_params { } @bind; } +sub _flatten_bind_params { + my ($self, @bind) = @_; + + ### Turn @bind from something like this: + ### ( [ "artist", 1 ], [ "cdid", 1, 3 ] ) + ### to this: + ### ( 1, 1, 3 ) + return + map { + if ( defined( $_ && $_->[1] ) ) { + @{$_}[ 1 .. $#$_ ]; + } + else { undef; } + } @bind; +} + sub _query_start { my ( $self, $sql, @bind ) = @_; @@ -1191,13 +1207,25 @@ sub _per_row_update_delete { sub _select { my $self = shift; + + # localization is neccessary as + # 1) there is no infrastructure to pass this around (easy to do, but will wait) + # 2) _select_args sets it and _prep_for_execute consumes it my $sql_maker = $self->sql_maker; + local $sql_maker->{for}; + return $self->_execute($self->_select_args(@_)); } sub _select_args_to_query { my $self = shift; + # localization is neccessary as + # 1) there is no infrastructure to pass this around (easy to do, but will wait) + # 2) _select_args sets it and _prep_for_execute consumes it + my $sql_maker = $self->sql_maker; + local $sql_maker->{for}; + # my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order, $rows, $offset) # = $self->_select_args($ident, $select, $cond, $attrs); my ($op, $bind, $ident, $bind_attrs, @args) = @@ -1205,17 +1233,19 @@ sub _select_args_to_query { # my ($sql, $prepared_bind) = $self->_prep_for_execute($op, $bind, $ident, [ $select, $cond, $order, $rows, $offset ]); my ($sql, $prepared_bind) = $self->_prep_for_execute($op, $bind, $ident, \@args); + $prepared_bind ||= []; - return \[ "($sql)", @{ $prepared_bind || [] }]; + return wantarray + ? ($sql, $prepared_bind, $bind_attrs) + : \[ "($sql)", @$prepared_bind ] + ; } sub _select_args { my ($self, $ident, $select, $condition, $attrs) = @_; - my $for = delete $attrs->{for}; my $sql_maker = $self->sql_maker; - - local $sql_maker->{for} = $for; + $sql_maker->{for} = delete $attrs->{for}; my $order = { map { $attrs->{$_} ? ( $_ => $attrs->{$_} ) : () } @@ -1284,21 +1314,28 @@ sub _resolve_ident_sources { $tabinfo = $_->[0]; } - $alias2source->{$tabinfo->{-alias}} = $tabinfo->{-result_source} - if ($tabinfo->{-result_source}); + $alias2source->{$tabinfo->{-alias}} = $tabinfo->{-source_handle}->resolve + if ($tabinfo->{-source_handle}); } } return $alias2source; } -sub count { +sub _copy_attributes_for_count { my ($self, $source, $attrs) = @_; + my %attrs = %$attrs; - my $tmp_attrs = { %$attrs }; + # take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count + delete @attrs{qw/select as rows offset page order_by record_filter/}; + + return \%attrs; +} + +sub count { + my ($self, $source, $attrs) = @_; - # take off any pagers, record_filter is cdbi, and no point of ordering a count - delete $tmp_attrs->{$_} for (qw/select as rows offset page order_by record_filter/); + my $tmp_attrs = $self->_copy_attributes_for_count($source, $attrs); # overwrite the selector $tmp_attrs->{select} = { count => '*' }; @@ -1322,7 +1359,7 @@ sub count_grouped { my $sub_attrs = { %$attrs }; # these can not go in the subquery, and there is no point of ordering it - delete $sub_attrs->{$_} for qw/prefetch collapse select as order_by/; + delete $sub_attrs->{$_} for qw/collapse select as order_by/; # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all # simply deleting group_by suffices, as the code below will re-fill it @@ -1339,7 +1376,7 @@ sub count_grouped { }]; # the subquery replaces this - delete $attrs->{$_} for qw/where bind prefetch collapse group_by having having_bind rows offset page pager/; + delete $attrs->{$_} for qw/where bind collapse group_by having having_bind rows offset/; return $self->count ($source, $attrs); }