From: Matt S Trout Date: Sun, 16 Sep 2018 20:47:11 +0000 (+0000) Subject: resolve final 02where fail by adding -func, 01generate still sad X-Git-Tag: v2.000000~3^2~480 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=da1c0f36bfae6d77ae6e367af524058696397d6f;p=dbsrgits%2FSQL-Abstract.git resolve final 02where fail by adding -func, 01generate still sad --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 7deced8..06dadb1 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -56,6 +56,7 @@ my @BUILTIN_UNARY_OPS = ( { regex => qr/^ op $/xi, handler => '_where_op_OP' }, { regex => qr/^ bind $/xi, handler => '_where_op_BIND' }, { regex => qr/^ literal $/xi, handler => '_where_op_LITERAL' }, + { regex => qr/^ func $/xi, handler => '_where_op_FUNC' }, ); #====================================================================== @@ -645,10 +646,18 @@ sub _expand_expr_hashpair { if ($k eq '-value' and my $m = our $Cur_Col_Meta) { return +{ -bind => [ $m, $v ] }; } - if ($k eq '-op' or $k eq '-ident' or $k eq '-value' or $k eq '-bind' or $k eq '-literal') { + if ($k eq '-op' or $k eq '-ident' or $k eq '-value' or $k eq '-bind' or $k eq '-literal' or $k eq '-func') { return { $k => $v }; } - if (!ref($v)) { + if ( + ref($v) eq 'HASH' + and keys %$v == 1 + and (keys %$v)[0] =~ /^-/ + ) { + my ($func) = $k =~ /^-(.*)$/; + return +{ -func => [ $func, $self->_expand_expr($v) ] }; + } + if (!ref($v) or is_literal_value($v)) { return +{ -op => [ $k =~ /^-(.*)$/, $self->_expand_expr($v) ] }; } } @@ -1281,6 +1290,18 @@ sub _where_op_OP { die "unhandled"; } +sub _where_op_FUNC { + my ($self, undef, $rest) = @_; + my ($func, @args) = @$rest; + my @arg_sql; + my @bind = map { + my @x = @$_; + push @arg_sql, shift @x; + @x + } map [ $self->_recurse_where($_) ], @args; + return ($self->_sqlcase($func).'('.join(', ', @arg_sql).')', @bind); +} + sub _where_op_BIND { my ($self, undef, $bind) = @_; return ($self->_convert('?'), $self->_bindtype(@$bind));