From 7613aa590880c0ed2397e04cc7b17efdca2169e3 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 27 Jun 2009 09:41:56 +0000 Subject: - Patch #369314 by Berdir: make sub-selects work. --- modules/simpletest/tests/database_test.test | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'modules/simpletest/tests/database_test.test') diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test index 6256ff22c..1ecf9c536 100644 --- a/modules/simpletest/tests/database_test.test +++ b/modules/simpletest/tests/database_test.test @@ -1364,6 +1364,29 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase { $this->assertEqual(count($people), 1, t('Returned the correct number of rows.')); } + /** + * Test that we can use a subquery in a FROM clause. + */ + function testConditionSubquerySelect() { + // Create a subquery, which is just a normal query object. + $subquery = db_select('test_task', 'tt'); + $subquery->addField('tt', 'pid', 'pid'); + $subquery->condition('tt.priority', 1); + + // Create another query that joins against the virtual table resulting + // from the subquery. + $select = db_select('test_task', 'tt2'); + $select->addField('tt2', 'task'); + $select->condition('tt2.pid', $subquery, 'IN'); + + // The resulting query should be equivalent to: + // SELECT tt2.name + // FROM test tt2 + // WHERE tt2.pid IN (SELECT tt.pid AS pid FROM test_task tt WHERE tt.priority=1) + $people = $select->execute()->fetchCol(); + $this->assertEqual(count($people), 5, t('Returned the correct number of rows.')); + } + /** * Test that we can use a subquery in a JOIN clause. */ -- cgit v1.2.3