Permalink
Browse files

Fix stupid assumption in parenthesis unroller

  • Loading branch information...
1 parent e82e648 commit 6e9a377bd3915ce41ee6a7d5e8db20928f852379 @ribasushi ribasushi committed Dec 5, 2010
Showing with 18 additions and 16 deletions.
  1. +4 −0 lib/SQL/Abstract/Tree.pm
  2. +2 −2 t/01generate.t
  3. +12 −14 t/10test.t
View
@@ -527,6 +527,7 @@ my @unrollable_ops = (
'GROUP \s+ BY',
'HAVING',
'ORDER \s+ BY',
+ 'I?LIKE',
);
my $unrollable_ops_re = join ' | ', @unrollable_ops;
$unrollable_ops_re = qr/$unrollable_ops_re/xi;
@@ -573,11 +574,14 @@ sub _parenthesis_unroll {
}
# only *ONE* LITERAL or placeholder element
+ # as an AND/OR/NOT argument
elsif (
@{$child->[1]} == 1 && (
$child->[1][0][0] eq 'LITERAL'
or
$child->[1][0][0] eq 'PLACEHOLDER'
+ ) && (
+ $ast->[0] eq 'AND' or $ast->[0] eq 'OR' or $ast->[0] eq 'NOT'
)
) {
push @children, $child->[1][0];
View
@@ -442,8 +442,8 @@ my @tests = (
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 ? )",
+ 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']],
},
{
View
@@ -643,33 +643,31 @@ my @sql_tests = (
'SELECT foo FROM bar ()',
]
},
- # single ? of unknown funcs can unroll
- # (think ...LIKE ?...)
{
- equal => 1,
+ equal => 0,
statements => [
- 'SELECT foo FROM bar WHERE bar > foo ?',
- 'SELECT foo FROM bar WHERE bar > foo (?)',
- 'SELECT foo FROM bar WHERE bar > foo( ? )',
+ 'SELECT COUNT * FROM foo',
+ 'SELECT COUNT( * ) FROM foo',
]
},
+ # single ? of unknown funcs do not unroll unless
+ # explicitly allowed (e.g. Like)
{
- equal => 1,
+ equal => 0,
statements => [
- 'SELECT foo FROM bar WHERE bar > (foo ?)',
- 'SELECT foo FROM bar WHERE bar > (foo( ? ))',
- 'SELECT foo FROM bar WHERE bar > (( foo (?) ))',
+ 'SELECT foo FROM bar WHERE bar > foo ?',
+ 'SELECT foo FROM bar WHERE bar > foo( ? )',
]
},
{
equal => 1,
statements => [
- 'SELECT foo FROM bar WHERE bar foo ?',
- 'SELECT foo FROM bar WHERE bar foo (?)',
- 'SELECT foo FROM bar WHERE bar foo( (?))',
+ 'SELECT foo FROM bar WHERE bar LIKE ?',
+ 'SELECT foo FROM bar WHERE bar LiKe (?)',
+ 'SELECT foo FROM bar WHERE bar lIkE( (?))',
]
},
- # not so about multival
+ # test multival
{
equal => 0,
statements => [

0 comments on commit 6e9a377

Please sign in to comment.