7 use SQL::Abstract::Test import => ['is_same_sql_bind'];
8 $SQL::Abstract::Test::parenthesis_significant = 1;
12 my $sql = SQL::Abstract->new;
14 my (@tests, $sub_stmt, @sub_bind, $where);
17 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
21 bar => \["IN ($sub_stmt)" => @sub_bind],
25 stmt => " WHERE ( ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? ) )",
26 bind => [100, "foo%", 1234],
30 ($sub_stmt, @sub_bind)
31 = $sql->select("t1", "c1", {c2 => {"<" => 100},
32 c3 => {-like => "foo%"}});
35 bar => \["> ALL ($sub_stmt)" => @sub_bind],
39 stmt => " WHERE ( ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? ) )",
40 bind => [100, "foo%", 1234],
44 ($sub_stmt, @sub_bind)
45 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
48 -paren => \["EXISTS ($sub_stmt)" => @sub_bind],
52 stmt => " WHERE ( ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? ) )",
58 -paren => \["MATCH (col1, col2) AGAINST (?)" => "apples"],
62 stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )",
68 ($sub_stmt, @sub_bind)
69 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
70 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
72 lname => {-like => '%son%'},
73 -paren => \["NOT ( $sub_stmt )" => @sub_bind],
77 stmt => " WHERE ( ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? ) )",
78 bind => [10, 20, '%son%'],
82 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
86 bar => { -in => \[$sub_stmt => @sub_bind] },
90 stmt => " WHERE ( ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? ) )",
91 bind => [100, "foo%", 1234],
95 plan tests => scalar(@tests);
99 my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
100 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});