5 use SQL::Abstract::Test import => ['is_same_sql_bind'];
11 # -nest has been undocumented on purpose, but is still supported for the
12 # foreseable future. Do not rip out the -nest tests before speaking to
13 # someone on the DBIC mailing list or in irc.perl.org#dbix-class
18 my $sql = SQL::Abstract->new;
20 my (@tests, $sub_stmt, @sub_bind, $where);
23 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
27 bar => \["IN ($sub_stmt)" => @sub_bind],
31 stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
32 bind => [100, "foo%", 1234],
36 ($sub_stmt, @sub_bind)
37 = $sql->select("t1", "c1", {c2 => {"<" => 100},
38 c3 => {-like => "foo%"}});
41 bar => \["> ALL ($sub_stmt)" => @sub_bind],
45 stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE (( c2 < ? AND c3 LIKE ? )) ) AND foo = ? )",
46 bind => [100, "foo%", 1234],
50 ($sub_stmt, @sub_bind)
51 = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
54 -nest => \["EXISTS ($sub_stmt)" => @sub_bind],
58 stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )",
64 -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"],
68 stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )",
74 ($sub_stmt, @sub_bind)
75 = $sql->where({age => [{"<" => 10}, {">" => 20}]});
76 $sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
78 lname => {-like => '%son%'},
79 -nest => \["NOT ( $sub_stmt )" => @sub_bind],
83 stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )",
84 bind => [10, 20, '%son%'],
88 ($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
92 bar => { -in => \[$sub_stmt => @sub_bind] },
96 stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
97 bind => [100, "foo%", 1234],
102 my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
103 is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});