From: Matt S Trout Date: Sun, 17 Nov 2013 06:06:12 +0000 (+0000) Subject: add Perl operator conversion support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6da919774e426fd5ca14d06985934657e1199590;p=dbsrgits%2FSQL-Abstract.git add Perl operator conversion support --- diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index 935b601..d3cce0a 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -268,6 +268,18 @@ sub _where_to_dq { return $self->_expr_to_dq($where, $logic); } +my %op_conversions = ( + '==' => '=', + 'eq' => '=', + 'ne' => '!=', + '!' => 'NOT', + 'gt' => '>', + 'ge' => '>=', + 'lt' => '<', + 'le' => '<=', + 'defined' => 'IS NOT NULL', +); + sub _expr_to_dq { my ($self, $where, $logic) = @_; @@ -281,7 +293,20 @@ sub _expr_to_dq { ) { return $self->_literal_to_dq($$where); } elsif (ref($where) eq 'REF' and ref($$where) eq 'HASH') { - return $$where; + return map_dq_tree { + if ( + is_Operator + and not $_->{operator}{'SQL.Naive'} + and my $op = $_->{operator}{'Perl'} + ) { + my $sql_op = $op_conversions{$op} || uc($op); + return +{ + %{$_}, + operator => { 'SQL.Naive' => $sql_op } + }; + } + return $_; + } $$where; } elsif (!ref($where) or Scalar::Util::blessed($where)) { return $self->_value_to_dq($where); }