op => '_expand_op',
func => '_expand_func',
values => '_expand_values',
- bind => '_expand_noop',
- literal => '_expand_noop',
- keyword => '_expand_noop',
},
expand_op => {
'between' => '_expand_between',
my $op = $self->_normalize_op($k);
- { # Old SQLA compat
+ my $wsop = join(' ', split '_', $op);
- my $op = join(' ', split '_', $op);
+ my $is_special = List::Util::first { $wsop =~ $_->{regex} }
+ @{$self->{special_ops}};
+
+ { # Old SQLA compat
# the old special op system requires illegality for top-level use
if (
(our $Expand_Depth) == 1
and (
- List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}}
+ $is_special
or (
$self->{disable_old_special_ops}
- and List::Util::first { $op =~ $_->{regex} } @BUILTIN_SPECIAL_OPS
+ and List::Util::first { $wsop =~ $_->{regex} } @BUILTIN_SPECIAL_OPS
)
)
) {
- puke "Illegal use of top-level '-$op'"
+ puke "Illegal use of top-level '-$wsop'"
}
}
return $self->$exp($op, $v);
}
+ if ($self->{render}{$op}) {
+ return { "-${op}" => $v };
+ }
+
# Ops prefixed with -not_ get converted
if (my ($rest) = $op =~/^not_(.*)$/) {
}
}
- my $type = (
- $self->{unknown_unop_always_func} && !$self->{render_op}{$op}
- ? -func
- : -op
- );
+ my $type = $is_special || $self->{render_op}{$op} ? -op : -func;
- { # Old SQLA compat
+ if ($self->{restore_old_unop_handling}) {
+
+ # Old SQLA compat
if (
ref($v) eq 'HASH'
and keys %$v == 1
and (keys %$v)[0] =~ /^-/
+ and not $self->{render_op}{$op}
+ and not $is_special
) {
- $type = (
- (
- (List::Util::first { $op =~ $_->{regex} } @{$self->{special_ops}})
- or $self->{render_op}{$op}
- )
- ? -op
- : -func
- )
+ $type = -func;
+ } else {
+ $type = -op;
}
}
sub _render_keyword {
my ($self, undef, $keyword) = @_;
- return [ $self->_sqlcase(join ' ', split '_', $keyword) ];
+ return [ $self->_sqlcase(
+ ref($keyword) ? $$keyword : join ' ', split '_', $keyword
+ ) ];
}
sub _render_op {
sub _render_unop_prefix {
my ($self, $op, $v) = @_;
+ my $op_sql = $self->{restore_old_unop_handling}
+ ? $self->_sqlcase($op)
+ : { -keyword => $op };
return $self->join_query_parts(' ',
- $self->_sqlcase($op), $v->[0]
+ ($self->{restore_old_unop_handling}
+ ? $self->_sqlcase($op)
+ : { -keyword => \$op }),
+ $v->[0]
);
}
}
}
-sub _join_sql_clauses {
- my ($self, $logic, $clauses_aref, $bind_aref) = @_;
-
- if (@$clauses_aref > 1) {
- my $join = " " . $self->_sqlcase($logic) . " ";
- my $sql = '( ' . join($join, @$clauses_aref) . ' )';
- return ($sql, @$bind_aref);
- }
- elsif (@$clauses_aref) {
- return ($clauses_aref->[0], @$bind_aref); # no parentheses
- }
- else {
- return (); # if no SQL, ignore @$bind_aref
- }
-}
-
-
# Fix SQL case, if so requested
sub _sqlcase {
# LDNOTE: if $self->{case} is true, then it contains 'lower', so we