From: Peter Rabbitson Date: Wed, 27 Aug 2014 06:32:52 +0000 (+0200) Subject: Make sure cond collapser works case insensitively X-Git-Tag: v0.082800~71 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=953d5b7d978136fb5f43339f1b7b41d140b3e4a5;p=dbsrgits%2FDBIx-Class.git Make sure cond collapser works case insensitively --- diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index d2d8f63..90bade8 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -1031,7 +1031,7 @@ sub _collapse_cond { (ref $_ ne 'ARRAY' or !@$_) and $_ = [ -and => $_ ] for ($l, $r); - if (@$l and @$r and $l->[0] eq $r->[0] and $l->[0] eq '-and') { + if (@$l and @$r and $l->[0] eq $r->[0] and $l->[0] =~ /^\-and$/i) { $fin->{$col} = [ -and => map { @$_[1..$#$_] } ($l, $r) ]; } else { @@ -1188,7 +1188,7 @@ sub _collapse_cond_unroll_pairs { unshift @$pairs, $lhs => $rhs->[1]; } else { - push @conds, { $lhs => $rhs }; + push @conds, { $lhs => [ @{$rhs}[1..$#$rhs] ] }; } } elsif (@$rhs == 1) { diff --git a/t/sqlmaker/dbihacks_internals.t b/t/sqlmaker/dbihacks_internals.t index b15dc42..1214638 100644 --- a/t/sqlmaker/dbihacks_internals.t +++ b/t/sqlmaker/dbihacks_internals.t @@ -94,8 +94,8 @@ for my $t ( efcc_n_result => { artistid => 1, charfield => undef }, }, { - where => { artistid => { '=' => [ 1 ], }, charfield => { '=' => [-and => \'1', \['?',2] ] }, rank => { '=' => [ $num, $num ] } }, - cc_result => { artistid => 1, charfield => [ -and => { '=' => \['?',2] }, { '=' => \'1' } ], rank => { '=' => [$num, $num] } }, + where => { artistid => { '=' => [ 1 ], }, charfield => { '=' => [ -AND => \'1', \['?',2] ] }, rank => { '=' => [ -OR => $num, $num ] } }, + cc_result => { artistid => 1, charfield => [-and => { '=' => \['?',2] }, { '=' => \'1' } ], rank => { '=' => [$num, $num] } }, sql => 'WHERE artistid = ? AND charfield = 1 AND charfield = ? AND ( rank = ? OR rank = ? )', collapsed_sql => 'WHERE artistid = ? AND charfield = ? AND charfield = 1 AND ( rank = ? OR rank = ? )', efcc_result => { artistid => 1, charfield => UNRESOLVABLE_CONDITION }, @@ -227,7 +227,10 @@ for my $t ( for my $w ( $t->{where}, + $t->{where}, # do it twice, make sure we didn't destory the condition [ -and => $t->{where} ], + [ -AND => $t->{where} ], + { -OR => [ -AND => $t->{where} ] }, ( keys %{$t->{where}} <= 1 ? [ %{$t->{where}} ] : () ), ( (keys %{$t->{where}} == 1 and $t->{where}{-or}) ? ( ref $t->{where}{-or} eq 'HASH'