{
func => 'select',
args => ['Yo Momma', '*', { user => 'nwiger',
- -nest => [ workhrs => {'>', 20}, geo => 'ASIA' ] }],
- stmt => 'SELECT * FROM Yo Momma WHERE ( ( ( workhrs > ? ) OR ( geo = ? ) ) AND user = ? )',
- stmt_q => 'SELECT * FROM `Yo Momma` WHERE ( ( ( `workhrs` > ? ) OR ( `geo` = ? ) ) AND `user` = ? )',
+ -paren => [ workhrs => {'>', 20}, geo => 'ASIA' ] }],
+ stmt => 'SELECT * FROM Yo Momma WHERE ( ( ( workhrs > ? OR geo = ? ) AND user = ? ) )',
+ stmt_q => 'SELECT * FROM `Yo Momma` WHERE ( ( ( `workhrs` > ? OR `geo` = ? ) AND `user` = ? ) )',
bind => [qw(20 ASIA nwiger)],
+ keep_paren => 1,
},
#28
{
args => ['taco_punches', { one => 2, three => 4 },
{ bland => [ -and => {'!=', 'yes'}, {'!=', 'YES'} ],
tasty => { '!=', [qw(yes YES)] },
- -nest => [ face => [ -or => {'=', 'mr.happy'}, {'=', undef} ] ] },
+ -paren => [ face => [ -or => {'=', 'mr.happy'}, {'=', undef} ] ] },
],
stmt => 'UPDATE taco_punches SET one = ?, three = ? WHERE ( ( ( ( ( face = ? ) OR ( face IS NULL ) ) ) )'
. ' AND ( ( bland != ? ) AND ( bland != ? ) ) AND ( ( tasty != ? ) OR ( tasty != ? ) ) )',
stmt_q => 'UPDATE `taco_punches` SET `one` = ?, `three` = ? WHERE ( ( ( ( ( `face` = ? ) OR ( `face` IS NULL ) ) ) )'
. ' AND ( ( `bland` != ? ) AND ( `bland` != ? ) ) AND ( ( `tasty` != ? ) OR ( `tasty` != ? ) ) )',
bind => [qw(2 4 mr.happy yes YES yes YES)],
+ keep_paren => 1,
},
#29
{
func => 'select',
args => ['jeff', '*', { name => {'like', '%smith%', -not_in => ['Nate','Jim','Bob','Sally']},
- -nest => [ -or => [ -and => [age => { -between => [20,30] }, age => {'!=', 25} ],
+ -paren => [ -or => [ -and => [age => { -between => [20,30] }, age => {'!=', 25} ],
yob => {'<', 1976} ] ] } ],
- stmt => 'SELECT * FROM jeff WHERE ( ( ( ( ( ( ( age BETWEEN ? AND ? ) AND ( age != ? ) ) ) OR ( yob < ? ) ) ) )'
- . ' AND name NOT IN ( ?, ?, ?, ? ) AND name LIKE ? )',
- stmt_q => 'SELECT * FROM `jeff` WHERE ( ( ( ( ( ( ( `age` BETWEEN ? AND ? ) AND ( `age` != ? ) ) ) OR ( `yob` < ? ) ) ) )'
- . ' AND `name` NOT IN ( ?, ?, ?, ? ) AND `name` LIKE ? )',
- bind => [qw(20 30 25 1976 Nate Jim Bob Sally %smith%)]
+ stmt => 'SELECT * FROM jeff WHERE ( ( ( ( ( age BETWEEN ? AND ? ) AND age != ? ) OR yob < ? )'
+ . ' AND ( name NOT IN ( ?, ?, ?, ? ) AND name LIKE ? ) ) )',
+ stmt_q => 'SELECT * FROM `jeff` WHERE ( ( ( ( ( `age` BETWEEN ? AND ? ) AND `age` != ?) OR `yob` < ? )'
+ . ' AND ( `name` NOT IN ( ?, ?, ?, ? ) AND `name` LIKE ? ) ) )',
+ bind => [qw(20 30 25 1976 Nate Jim Bob Sally %smith%)],
+ keep_paren => 1,
},
#30
{
# acked by RIBASUSHI
# args => ['fhole', {fpoles => 4}, [-maybe => {race => [-and => [qw(black white asian)]]},
args => ['fhole', {fpoles => 4}, [ {race => [-and => [qw(black white asian)]]},
- {-nest => {firsttime => [-or => {'=','yes'}, undef]}},
+ {-paren => {firsttime => [-or => {'=','yes'}, undef]}},
[ -and => {firstname => {-not_like => 'candace'}}, {lastname => {-in => [qw(jugs canyon towers)]}} ] ] ],
- stmt => 'UPDATE fhole SET fpoles = ? WHERE ( ( ( ( ( ( ( race = ? ) OR ( race = ? ) OR ( race = ? ) ) ) ) ) )'
+ stmt => 'UPDATE fhole SET fpoles = ? WHERE ( ( ( ( ( ( race = ? OR ( race = ? ) OR ( race = ? ) ) ) ) ) )'
. ' OR ( ( ( ( firsttime = ? ) OR ( firsttime IS NULL ) ) ) ) OR ( ( ( firstname NOT LIKE ? ) ) AND ( lastname IN ( ?, ?, ? ) ) ) )',
stmt_q => 'UPDATE `fhole` SET `fpoles` = ? WHERE ( ( ( ( ( ( ( `race` = ? ) OR ( `race` = ? ) OR ( `race` = ? ) ) ) ) ) )'
. ' OR ( ( ( ( `firsttime` = ? ) OR ( `firsttime` IS NULL ) ) ) ) OR ( ( ( `firstname` NOT LIKE ? ) ) AND ( `lastname` IN ( ?, ?, ? ) ) ) )',
- bind => [qw(4 black white asian yes candace jugs canyon towers)]
+ bind => [qw(4 black white asian yes candace jugs canyon towers)],
+ keep_paren => 1,
+
},
#31
{
my $new = $_->{new} || {};
$new->{debug} = $ENV{DEBUG} || 0;
+ local $SQL::Abstract::Test::parenthesis_significant = $_->{keep_paren};
+
# test without quoting labels
{
my $sql = SQL::Abstract->new(%$new);
use Test::More;
use SQL::Abstract::Test import => ['is_same_sql_bind'];
+$SQL::Abstract::Test::parenthesis_significant = 1;
use SQL::Abstract;
};
push @tests, {
where => $where,
- stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
+ stmt => " WHERE ( ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? ) )",
bind => [100, "foo%", 1234],
};
};
push @tests, {
where => $where,
- stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? )",
+ stmt => " WHERE ( ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? ) )",
bind => [100, "foo%", 1234],
};
= $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
$where = {
foo => 1234,
- -nest => \["EXISTS ($sub_stmt)" => @sub_bind],
+ -paren => \["EXISTS ($sub_stmt)" => @sub_bind],
};
push @tests, {
where => $where,
- stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )",
+ stmt => " WHERE ( ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? ) )",
bind => [1, 1234],
};
#4
$where = {
- -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"],
+ -paren => \["MATCH (col1, col2) AGAINST (?)" => "apples"],
};
push @tests, {
where => $where,
$sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
$where = {
lname => {-like => '%son%'},
- -nest => \["NOT ( $sub_stmt )" => @sub_bind],
+ -paren => \["NOT ( $sub_stmt )" => @sub_bind],
};
push @tests, {
where => $where,
- stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )",
+ stmt => " WHERE ( ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? ) )",
bind => [10, 20, '%son%'],
};
};
push @tests, {
where => $where,
- stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
+ stmt => " WHERE ( ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? ) )",
bind => [100, "foo%", 1234],
};
my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});
}
-
-
-
-
-