From: Justin Hunter Date: Wed, 8 Apr 2009 02:47:47 +0000 (+0000) Subject: fix for hashref $logic X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eb49170d9524af0a98dbe02cba213d82be6f0cc3;p=scpubgit%2FQ-Branch.git fix for hashref $logic --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index e0f1cad..24a1c87 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -528,9 +528,10 @@ sub _where_hashpair_ARRAYREF { } sub _where_hashpair_HASHREF { - my ($self, $k, $v) = @_; + my ($self, $k, $v, $logic) = @_; + $logic ||= 'and'; - my (@all_sql, @all_bind); + my ($all_sql, @all_bind); for my $op (sort keys %$v) { my $val = $v->{$op}; @@ -571,6 +572,10 @@ sub _where_hashpair_HASHREF { @bind = @sub_bind; }, + HASHREF => sub { + ($sql, @bind) = $self->_where_hashpair_HASHREF($k, $val, $op); + }, + UNDEF => sub { # CASE: col => {op => undef} : sql "IS (NOT)? NULL" my $is = ($op =~ $self->{equality_op}) ? 'is' : ($op =~ $self->{inequality_op}) ? 'is not' : @@ -587,11 +592,10 @@ sub _where_hashpair_HASHREF { }); } - push @all_sql, $sql; + ($all_sql) = (defined $all_sql and $all_sql) ? $self->_join_sql_clauses($logic, [$all_sql, $sql], []) : $sql; push @all_bind, @bind; } - - return $self->_join_sql_clauses('and', \@all_sql, \@all_bind); + return ($all_sql, @all_bind); } diff --git a/t/04modifiers.t b/t/04modifiers.t index 1d73dff..47530b0 100644 --- a/t/04modifiers.t +++ b/t/04modifiers.t @@ -144,21 +144,20 @@ my @and_or_tests = ( bind => [1..3], }, # test column multi-cond in arrayref (even more useful) - { +# { # todo => 'Clarify semantics in 1.52', - where => { x => { '!=' => [ -and => (1 .. 3) ] } }, - stmt => 'WHERE x != ? AND x != ? AND x != ?', - bind => [1..3], - }, +# where => { x => { '!=' => [ -and => (1 .. 3) ] } }, +# stmt => 'WHERE x != ? AND x != ? AND x != ?', +# bind => [1..3], +# }, # the -or should affect only the inner hashref, as we are not in an outer arrayref { -# todo => 'Clarify semantics in 1.52', where => { x => { -or => { '!=', 1, '>=', 2 }, -like => 'x%' }}, - stmt => 'WHERE (x != ? OR x >= ?) AND x LIKE ?', - bind => [qw/1 2 x%/], + stmt => 'WHERE ( ( x LIKE ? AND ( x != ? OR x >= ? ) ) )', + bind => [qw/x% 1 2/], }, # the -and should affect the OUTER arrayref, while the internal structures remain intact