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'"
}
}
}
}
- 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_unop_prefix {
my ($self, $op, $v) = @_;
+ my $op_sql = $self->{restore_old_unop_handling}
+ ? $self->_sqlcase($op)
+ : { -keyword => $op };
return $self->join_query_parts(' ',
- { -keyword => \$op }, $v->[0]
+ ($self->{restore_old_unop_handling}
+ ? $self->_sqlcase($op)
+ : { -keyword => \$op }),
+ $v->[0]
);
}
func => 'update',
new => {bindtype => 'columns'},
args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']], c => { -lower => 'foo' }}, {a => {'between', [1,2]}}],
+ stmt => "UPDATE test SET a = ?, b = to_date(?, 'MM/DD/YY'), c = LOWER(?) WHERE ( a BETWEEN ? AND ? )",
+ stmt_q => "UPDATE `test` SET `a` = ?, `b` = to_date(?, 'MM/DD/YY'), `c` = LOWER(?) WHERE ( `a` BETWEEN ? AND ? )",
+ bind => [[a => '1'], [{dummy => 1} => '02/02/02'], [c => 'foo'], [a => '1'], [a => '2']],
+ },
+ {
+ func => 'update',
+ new => {bindtype => 'columns',restore_old_unop_handling => 1},
+ args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '02/02/02']], c => { -lower => 'foo' }}, {a => {'between', [1,2]}}],
stmt => "UPDATE test SET a = ?, b = to_date(?, 'MM/DD/YY'), c = LOWER ? WHERE ( a BETWEEN ? AND ? )",
stmt_q => "UPDATE `test` SET `a` = ?, `b` = to_date(?, 'MM/DD/YY'), `c` = LOWER ? WHERE ( `a` BETWEEN ? AND ? )",
bind => [[a => '1'], [{dummy => 1} => '02/02/02'], [c => 'foo'], [a => '1'], [a => '2']],
func => 'select',
new => {bindtype => 'columns'},
args => ['test', '*', [ Y => { '=' => { -max => { -LENGTH => { -min => 'x' } } } } ] ],
+ stmt => 'SELECT * FROM test WHERE ( Y = ( MAX( LENGTH( MIN(?) ) ) ) )',
+ stmt_q => 'SELECT * FROM `test` WHERE ( `Y` = ( MAX( LENGTH( MIN(?) ) ) ) )',
+ bind => [[Y => 'x']],
+ },
+ {
+ func => 'select',
+ new => {bindtype => 'columns',restore_old_unop_handling => 1},
+ args => ['test', '*', [ Y => { '=' => { -max => { -LENGTH => { -min => 'x' } } } } ] ],
stmt => 'SELECT * FROM test WHERE ( Y = ( MAX( LENGTH( MIN ? ) ) ) )',
stmt_q => 'SELECT * FROM `test` WHERE ( `Y` = ( MAX( LENGTH( MIN ? ) ) ) )',
bind => [[Y => 'x']],
# Op against random functions (these two are oracle-specific)
{
where => { timestamp => { '!=' => { -trunc => { -year => \'sysdate' } } } },
- stmt => " WHERE ( timestamp != TRUNC (YEAR sysdate) )",
+ stmt => " WHERE ( timestamp != TRUNC(YEAR(sysdate)) )",
bind => [],
},
{
where => { timestamp => { '>=' => { -to_date => '2009-12-21 00:00:00' } } },
- stmt => " WHERE ( timestamp >= TO_DATE ? )",
+ stmt => " WHERE ( timestamp >= TO_DATE(?) )",
bind => ['2009-12-21 00:00:00'],
},
] },
},
stmt => "WHERE (
+ ( start0 BETWEEN ? AND UPPER(?) )
+ AND ( start1 BETWEEN ? AND ? )
+ AND ( start2 BETWEEN lower(x) AND upper(y) )
+ AND ( start3 BETWEEN lower(x) AND upper(?) )
+ )",
+ bind => [1, 2, 1, 2, 'stuff'],
+ test => '-between POD test',
+ },
+ {
+ args => { restore_old_unop_handling => 1 },
+ where => {
+ start0 => { -between => [ 1, { -upper => 2 } ] },
+ start1 => { -between => \["? AND ?", 1, 2] },
+ start2 => { -between => \"lower(x) AND upper(y)" },
+ start3 => { -between => [
+ \"lower(x)",
+ \["upper(?)", 'stuff' ],
+ ] },
+ },
+ stmt => "WHERE (
( start0 BETWEEN ? AND UPPER ? )
AND ( start1 BETWEEN ? AND ? )
AND ( start2 BETWEEN lower(x) AND upper(y) )
] },
},
stmt => "WHERE (
+ ( start0 BETWEEN ? AND UPPER(?) )
+ AND ( start1 BETWEEN ? AND ? )
+ AND ( start2 BETWEEN lower(x) AND upper(y) )
+ AND ( start3 BETWEEN lower(x) AND upper(?) )
+ )",
+ bind => [
+ [ start0 => 1 ],
+ [ start0 => 2 ],
+ [ start1 => 1 ],
+ [ start1 => 2 ],
+ [ start3 => 'stuff' ],
+ ],
+ test => '-between POD test',
+ },
+ {
+ args => { restore_old_unop_handling => 1, bindtype => 'columns' },
+ where => {
+ start0 => { -between => [ 1, { -upper => 2 } ] },
+ start1 => { -between => \["? AND ?", [ start1 => 1], [start1 => 2] ] },
+ start2 => { -between => \"lower(x) AND upper(y)" },
+ start3 => { -between => [
+ \"lower(x)",
+ \["upper(?)", [ start3 => 'stuff'] ],
+ ] },
+ },
+ stmt => "WHERE (
( start0 BETWEEN ? AND UPPER ? )
AND ( start1 BETWEEN ? AND ? )
AND ( start2 BETWEEN lower(x) AND upper(y) )
{
where => { x => { -in => [ \['LOWER(?)', 'A' ], \'LOWER(b)', { -lower => 'c' } ] } },
+ stmt => " WHERE ( x IN ( LOWER(?), LOWER(b), LOWER(?) ) )",
+ bind => [qw/A c/],
+ test => '-in with an array of function array refs with args',
+ },
+ {
+ args => { restore_old_unop_handling => 1 },
+ where => { x => { -in => [ \['LOWER(?)', 'A' ], \'LOWER(b)', { -lower => 'c' } ] } },
stmt => " WHERE ( x IN ( LOWER(?), LOWER(b), LOWER ? ) )",
bind => [qw/A c/],
test => '-in with an array of function array refs with args',