diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php index b269410b8387375736d0f917f3b56e0ce7979507..a5e93e8e39e28aaba1ef0d5bd72e28d451ab9aec 100644 --- a/core/lib/Drupal/Core/Database/Query/Select.php +++ b/core/lib/Drupal/Core/Database/Query/Select.php @@ -660,7 +660,7 @@ public function orderRandom() { * {@inheritdoc} */ public function range($start = NULL, $length = NULL) { - $this->range = func_num_args() ? array('start' => $start, 'length' => $length) : array(); + $this->range = $start !== NULL ? array('start' => $start, 'length' => $length) : array(); return $this; } diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php index ccf153b2518efab24ce877720bd1a0ef8ac80b2f..d6da2548237e0206eb0114ae2b139a80c26c1add 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php @@ -154,6 +154,20 @@ function testRange() { $this->assertEqual($query_result, 2, 'Returned the correct number of rows.'); } + /** + * Test whether the range property of a select clause can be undone. + */ + function testRangeUndo() { + $query = db_select('test'); + $name_field = $query->addField('test', 'name'); + $age_field = $query->addField('test', 'age', 'age'); + $query->range(0, 2); + $query->range(NULL, NULL); + $query_result = $query->countQuery()->execute()->fetchField(); + + $this->assertEqual($query_result, 4, 'Returned the correct number of rows.'); + } + /** * Tests distinct queries. */