remove obsolete thing that never worked
[scpubgit/Q-Branch.git] / t / 07subqueries.t
index 85f973e..7d5fbd4 100644 (file)
-#!/usr/bin/perl\r
-\r
-use strict;\r
-use warnings;\r
-use Test::More;\r
-\r
-use SQL::Abstract::Test import => ['is_same_sql_bind'];\r
-\r
-use SQL::Abstract;\r
-\r
-my $sql = SQL::Abstract->new;\r
-\r
-my (@tests, $sub_stmt, @sub_bind, $where);\r
-\r
-#1\r
-($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",\r
-                          100, "foo%");\r
-$where = {\r
-    foo => 1234,\r
-    bar => \["IN ($sub_stmt)" => @sub_bind],\r
-  };\r
-push @tests, {\r
-  where => $where,\r
-  stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",\r
-  bind => [100, "foo%", 1234],\r
-};\r
-\r
-#2\r
-($sub_stmt, @sub_bind)\r
-     = $sql->select("t1", "c1", {c2 => {"<" => 100}, \r
-                                 c3 => {-like => "foo%"}});\r
-$where = {\r
-    foo => 1234,\r
-    bar => \["> ALL ($sub_stmt)" => @sub_bind],\r
-  };\r
-push @tests, {\r
-  where => $where,\r
-  stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? )",\r
-  bind => [100, "foo%", 1234],\r
-};\r
-\r
-#3\r
-($sub_stmt, @sub_bind) \r
-     = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});\r
-$where = {\r
-    foo                  => 1234,\r
-    -nest => \["EXISTS ($sub_stmt)" => @sub_bind],\r
-  };\r
-push @tests, {\r
-  where => $where,\r
-  stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )",\r
-  bind => [1, 1234],\r
-};\r
-\r
-#4\r
-$where = {\r
-    -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"],\r
-  };\r
-push @tests, {\r
-  where => $where,\r
-  stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )",\r
-  bind => ["apples"],\r
-};\r
-\r
-\r
-#5\r
-($sub_stmt, @sub_bind) \r
-  = $sql->where({age => [{"<" => 10}, {">" => 20}]});\r
-$sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause\r
-$where = {\r
-    lname  => {-like => '%son%'},\r
-    -nest  => \["NOT ( $sub_stmt )" => @sub_bind],\r
-  };\r
-push @tests, {\r
-  where => $where,\r
-  stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )",\r
-  bind => [10, 20, '%son%'],\r
-};\r
-\r
-\r
-plan tests => scalar(@tests);\r
-\r
-for (@tests) {\r
-\r
-  my($stmt, @bind) = $sql->where($_->{where}, $_->{order});\r
-  is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});\r
-}\r
-\r
-\r
-\r
-\r
-\r
+use strict;
+use warnings;
+use Test::More;
+
+use SQL::Abstract::Test import => ['is_same_sql_bind'];
+
+use SQL::Abstract;
+
+#### WARNING ####
+#
+# -nest has been undocumented on purpose, but is still supported for the
+# foreseable future. Do not rip out the -nest tests before speaking to
+# someone on the DBIC mailing list or in irc.perl.org#dbix-class
+#
+#################
+
+
+my $sql = SQL::Abstract->new;
+
+my (@tests, $sub_stmt, @sub_bind, $where);
+
+#1
+($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
+                          100, "foo%");
+$where = {
+    foo => 1234,
+    bar => \["IN ($sub_stmt)" => @sub_bind],
+  };
+push @tests, {
+  where => $where,
+  stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
+  bind => [100, "foo%", 1234],
+};
+
+#2
+($sub_stmt, @sub_bind)
+     = $sql->select("t1", "c1", {c2 => {"<" => 100},
+                                 c3 => {-like => "foo%"}});
+$where = {
+    foo => 1234,
+    bar => \["> ALL ($sub_stmt)" => @sub_bind],
+  };
+push @tests, {
+  where => $where,
+  stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE (( c2 < ? AND c3 LIKE ? )) ) AND foo = ? )",
+  bind => [100, "foo%", 1234],
+};
+
+#3
+($sub_stmt, @sub_bind)
+     = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"});
+$where = {
+    foo                  => 1234,
+    -nest => \["EXISTS ($sub_stmt)" => @sub_bind],
+  };
+push @tests, {
+  where => $where,
+  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"],
+  };
+push @tests, {
+  where => $where,
+  stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )",
+  bind => ["apples"],
+};
+
+
+#5
+($sub_stmt, @sub_bind)
+  = $sql->where({age => [{"<" => 10}, {">" => 20}]});
+$sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause
+$where = {
+    lname  => {-like => '%son%'},
+    -nest  => \["NOT ( $sub_stmt )" => @sub_bind],
+  };
+push @tests, {
+  where => $where,
+  stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )",
+  bind => [10, 20, '%son%'],
+};
+
+#6
+($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
+                          100, "foo%");
+$where = {
+    foo => 1234,
+    bar => { -in => \[$sub_stmt => @sub_bind] },
+  };
+push @tests, {
+  where => $where,
+  stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
+  bind => [100, "foo%", 1234],
+};
+
+for (@tests) {
+
+  my($stmt, @bind) = $sql->where($_->{where}, $_->{order});
+  is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind});
+}
+
+done_testing;