7 use SQL::Abstract::Test import => ['is_same_sql_bind'];
13 # -nest has been undocumented on purpose, but is still supported for the
14 # foreseable future. Do not rip out the -nest tests before speaking to
15 # someone on the DBIC mailing list or in irc.perl.org#dbix-class
20 my $sql = SQL::Abstract->new;
22 my (@tests, $sub_stmt, @sub_bind, $where);
25 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
29 bar => \["IN ($sub_stmt)" => @sub_bind],
33 stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
34 bind => [100, "foo%", 1234],
38 ($sub_stmt, @sub_bind)
39 = $sql->select("t1", "c1", {c2 => {"<" => 100},
40 c3 => {-like => "foo%"}});
43 bar => \["> ALL ($sub_stmt)" => @sub_bind],
47 stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE (( c2 < ? AND c3 LIKE ? )) ) AND foo = ? )",
48 bind => [100, "foo%", 1234],
52 ($sub_stmt, @sub_bind)
53 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
56 -nest => \["EXISTS ($sub_stmt)" => @sub_bind],
60 stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )",
66 -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"],
70 stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )",
76 ($sub_stmt, @sub_bind)
77 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
78 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
80 lname => {-like => '%son%'},
81 -nest => \["NOT ( $sub_stmt )" => @sub_bind],
85 stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )",
86 bind => [10, 20, '%son%'],
90 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
94 bar => { -in => \[$sub_stmt => @sub_bind] },
98 stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
99 bind => [100, "foo%", 1234],
104 my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
105 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});