X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBIHacks.pm;h=c700d54eb0a940ad1fbacd17dc2f79d340836a7e;hb=50841788d03e2342a00470eb2f458e717922615b;hp=c129b1e318b65af3b3c084e6424a55920f5a5ce5;hpb=07fadea8d16b657cc1ee572b8f64fa7a688be853;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index c129b1e..c700d54 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -28,9 +28,8 @@ use warnings; use base 'DBIx::Class::Storage'; use mro 'c3'; -use List::Util 'first'; use Scalar::Util 'blessed'; -use DBIx::Class::_Util qw(UNRESOLVABLE_CONDITION serialize); +use DBIx::Class::_Util qw(UNRESOLVABLE_CONDITION serialize dump_value); use SQL::Abstract qw(is_plain_value is_literal_value); use DBIx::Class::Carp; use namespace::clean; @@ -229,7 +228,8 @@ sub _adjust_select_args_for_complex_prefetch { my $inner_subq = do { # must use it here regardless of user requests (vastly gentler on optimizer) - local $self->{_use_join_optimizer} = 1; + local $self->{_use_join_optimizer} = 1 + unless $self->{_use_join_optimizer}; # throw away multijoins since we def. do not care about those inside the subquery # $inner_aliastypes *will* be redefined at this point @@ -344,7 +344,7 @@ sub _adjust_select_args_for_complex_prefetch { ) { push @outer_from, $j } - elsif (first { $_->{$alias} } @outer_nonselecting_chains ) { + elsif (grep { $_->{$alias} } @outer_nonselecting_chains ) { push @outer_from, $j; $may_need_outer_group_by ||= $outer_aliastypes->{multiplying}{$alias} ? 1 : 0; } @@ -513,9 +513,9 @@ sub _resolve_aliastypes_from_select_args { ( $_ = join ' ', map { ( ! defined $_ ) ? () - : ( length ref $_ ) ? (require Data::Dumper::Concise && $self->throw_exception( - "Unexpected ref in scan-plan: " . Data::Dumper::Concise::Dumper($_) - )) + : ( length ref $_ ) ? $self->throw_exception( + "Unexpected ref in scan-plan: " . dump_value $_ + ) : ( $_ =~ /^\s*$/ ) ? () : $_ @@ -720,6 +720,8 @@ sub _group_over_selection { # for DESC, and group_by the root columns. The end result should be # exactly what we expect # + + # both populated on the first loop over $o_idx $sql_maker ||= $self->sql_maker; $order_chunks ||= [ map { ref $_ eq 'ARRAY' ? $_ : [ $_ ] } $sql_maker->_order_by_chunks($attrs->{order_by}) @@ -731,7 +733,7 @@ sub _group_over_selection { # to an ordering alias into a MIN/MAX $new_order_by[$o_idx] = \[ sprintf( '%s( %s )%s', - ($is_desc ? 'MAX' : 'MIN'), + $self->_minmax_operator_for_datatype($chunk_ci->{data_type}, $is_desc), $chunk, ($is_desc ? ' DESC' : ''), ), @@ -759,6 +761,12 @@ sub _group_over_selection { ); } +sub _minmax_operator_for_datatype { + #my ($self, $datatype, $want_max) = @_; + + $_[2] ? 'MAX' : 'MIN'; +} + sub _resolve_ident_sources { my ($self, $ident) = @_; @@ -1102,7 +1110,7 @@ sub _collapse_cond { for (sort keys %$chunk) { # Match SQLA 1.79 behavior - if ($_ eq '') { + unless( length $_ ) { is_literal_value($chunk->{$_}) ? carp 'Hash-pairs consisting of an empty string with a literal are deprecated, use -and => [ $literal ] instead' : $self->throw_exception("Supplying an empty left hand side argument is not supported in hash-pairs") @@ -1120,7 +1128,7 @@ sub _collapse_cond { # Match SQLA 1.79 behavior $self->throw_exception("Supplying an empty left hand side argument is not supported in array-pairs") - if $where_is_anded_array and (! defined $chunk or $chunk eq ''); + if $where_is_anded_array and (! defined $chunk or ! length $chunk); push @pairs, $chunk, shift @pieces; } @@ -1315,7 +1323,7 @@ sub _collapse_cond_unroll_pairs { while (@$pairs) { my ($lhs, $rhs) = splice @$pairs, 0, 2; - if ($lhs eq '') { + if (! length $lhs) { push @conds, $self->_collapse_cond($rhs); } elsif ( $lhs =~ /^\-and$/i ) { @@ -1346,11 +1354,10 @@ sub _collapse_cond_unroll_pairs { # extra sanity check if (keys %$p > 1) { - require Data::Dumper::Concise; local $Data::Dumper::Deepcopy = 1; $self->throw_exception( "Internal error: unexpected collapse unroll:" - . Data::Dumper::Concise::Dumper { in => { $lhs => $rhs }, out => $p } + . dump_value { in => { $lhs => $rhs }, out => $p } ); }