Commit fa622be1 authored by webchick's avatar webchick

#1001242 follow-up by bfroehle, Steven Jones: Fix EXISTS tests for SQLite and PostgreSQL.

parent b793fc9e
...@@ -1687,6 +1687,9 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase { ...@@ -1687,6 +1687,9 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
/** /**
* Test EXISTS subquery conditionals on SELECT statements. * Test EXISTS subquery conditionals on SELECT statements.
*
* We essentially select all rows from the {test} table that have matching
* rows in the {test_people} table based on the shared name column.
*/ */
function testExistsSubquerySelect() { function testExistsSubquerySelect() {
// Put George into {test_people}. // Put George into {test_people}.
...@@ -1703,7 +1706,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase { ...@@ -1703,7 +1706,7 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// Subquery to {test_people}. // Subquery to {test_people}.
$subquery = db_select('test_people', 'tp') $subquery = db_select('test_people', 'tp')
->fields('tp', array('name')) ->fields('tp', array('name'))
->condition('name', 'George'); ->where('tp.name = t.name');
$query->exists($subquery); $query->exists($subquery);
$result = $query->execute(); $result = $query->execute();
...@@ -1714,6 +1717,9 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase { ...@@ -1714,6 +1717,9 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
/** /**
* Test NOT EXISTS subquery conditionals on SELECT statements. * Test NOT EXISTS subquery conditionals on SELECT statements.
*
* We essentially select all rows from the {test} table that don't have
* matching rows in the {test_people} table based on the shared name column.
*/ */
function testNotExistsSubquerySelect() { function testNotExistsSubquerySelect() {
// Put George into {test_people}. // Put George into {test_people}.
...@@ -1731,13 +1737,12 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase { ...@@ -1731,13 +1737,12 @@ class DatabaseSelectSubqueryTestCase extends DatabaseTestCase {
// Subquery to {test_people}. // Subquery to {test_people}.
$subquery = db_select('test_people', 'tp') $subquery = db_select('test_people', 'tp')
->fields('tp', array('name')) ->fields('tp', array('name'))
->condition('name', 'George'); ->where('tp.name = t.name');
$query->notExists($subquery); $query->notExists($subquery);
$result = $query->execute();
// Ensure that we got the right record. // Ensure that we got the right number of records.
$record = $result->fetch(); $people = $query->execute()->fetchCol();
$this->assertFalse($record, t('NOT EXISTS query returned no results.')); $this->assertEqual(count($people), 3, t('NOT EXISTS query returned the correct results.'));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment