From 85fe0a861d0752aa4c8b046a8f12e9f43c5ec15e Mon Sep 17 00:00:00 2001
From: Jorrit Schippers <jorrit@161217.no-reply.drupal.org>
Date: Mon, 8 Oct 2012 18:10:25 +0200
Subject: [PATCH] Issue #1806606 by Jorrit: Fixed behavior of
 Select::range($start, $length) method when $start is NULL.

---
 core/lib/Drupal/Core/Database/Query/Select.php     |    2 +-
 .../system/Tests/Database/SelectComplexTest.php    |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php
index 22aca8f..2bd52fe 100644
--- a/core/lib/Drupal/Core/Database/Query/Select.php
+++ b/core/lib/Drupal/Core/Database/Query/Select.php
@@ -551,7 +551,7 @@ public function orderRandom() {
   }
 
   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/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php
index e8a1d1e..c485765 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Database/SelectComplexTest.php
@@ -166,6 +166,25 @@ function testRange() {
   }
 
   /**
+   * 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);
+    $result = $query->execute();
+
+    $num_records = 0;
+    foreach ($result as $record) {
+      $num_records++;
+    }
+
+    $this->assertEqual($num_records, 4, 'Returned the correct number of rows.');
+  }
+
+  /**
    * Test distinct queries.
    */
   function testDistinct() {
-- 
1.7.9.5

