7 use SQL::Abstract::Test import => ['is_same_sql_bind'];
11 my $sql = SQL::Abstract->new;
13 my (@tests, $sub_stmt, @sub_bind, $where);
16 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
20 bar => \["IN ($sub_stmt)" => @sub_bind],
24 stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
25 bind => [100, "foo%", 1234],
29 ($sub_stmt, @sub_bind)
30 = $sql->select("t1", "c1", {c2 => {"<" => 100},
31 c3 => {-like => "foo%"}});
34 bar => \["> ALL ($sub_stmt)" => @sub_bind],
38 stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? )",
39 bind => [100, "foo%", 1234],
43 ($sub_stmt, @sub_bind)
44 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
47 -nest => \["EXISTS ($sub_stmt)" => @sub_bind],
51 stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )",
57 -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"],
61 stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )",
67 ($sub_stmt, @sub_bind)
68 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
69 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
71 lname => {-like => '%son%'},
72 -nest => \["NOT ( $sub_stmt )" => @sub_bind],
76 stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )",
77 bind => [10, 20, '%son%'],
81 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
85 bar => { -in => \[$sub_stmt => @sub_bind] },
89 stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
90 bind => [100, "foo%", 1234],
94 plan tests => scalar(@tests);
98 my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
99 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});