From: Matt S Trout Date: Thu, 21 Mar 2019 04:02:55 +0000 (+0000) Subject: op rendering w/postfix X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b23fd5ffc63da6046b36d4926e575b4c1935e8b4;p=scpubgit%2FQ-Branch.git op rendering w/postfix --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 3a52e90..53a92b0 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -988,9 +988,8 @@ sub _render_literal { our $RENDER_OP = { (map +($_ => do { - my $op = $_; sub { - my ($self, $args) = @_; + my ($self, $op, $args) = @_; my ($left, $low, $high) = @$args; my ($rhsql, @rhbind) = do { if (@$args == 2) { @@ -1011,9 +1010,8 @@ our $RENDER_OP = { } }), 'between', 'not between'), (map +($_ => do { - my $op = $_; sub { - my ($self, $args) = @_; + my ($self, $op, $args) = @_; my ($lhs, $rhs) = @$args; my @in_bind; my @in_sql = map { @@ -1030,6 +1028,9 @@ our $RENDER_OP = { ); } }), 'in', 'not in'), + (map +($_ => '_render_unop_postfix'), + 'is null', 'is not null', 'asc', 'desc', + ), }; my %unop_postfix = map +($_ => 1), @@ -1041,7 +1042,7 @@ sub _render_op { my ($self, $v) = @_; my ($op, @args) = @$v; if (my $r = $self->{render_op}{$op}) { - return $self->$r(\@args); + return $self->$r($op, \@args); } my $us = List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}; if ($us and @args > 1) { @@ -1080,6 +1081,15 @@ sub _render_op { die "unhandled"; } +sub _render_unop_postfix { + my ($self, $op, $v) = @_; + my ($arg, @argh) = @$v; + puke "Argh" if @argh; + my ($expr_sql, @bind) = $self->render_aqt($arg); + my $op_sql = $self->_sqlcase($op); + return ($expr_sql.' '.$op_sql, @bind); +} + # Some databases (SQLite) treat col IN (1, 2) different from # col IN ( (1, 2) ). Use this to strip all outer parens while # adding them back in the corresponding method