? 903110.patch
Index: includes/pager.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/pager.inc,v
retrieving revision 1.81
diff -u -p -r1.81 pager.inc
--- includes/pager.inc	4 Aug 2010 03:46:16 -0000	1.81
+++ includes/pager.inc	6 Sep 2010 18:28:10 -0000
@@ -82,16 +82,16 @@ class PagerDefault extends SelectQueryEx
 
   /**
    * Ensure that there is an element associated with this query.
+   * If an element was not specified previously, then the value of the
+   * $maxElement counter is taken, after which the counter is incremented.
    *
-   * After running this query, access $this->element to get the element for this
+   * After running this method, access $this->element to get the element for this
    * query.
    */
   protected function ensureElement() {
-    if (!empty($this->element)) {
-      return;
+    if (!isset($this->element)) {
+      $this->element = self::$maxElement++;
     }
-
-    $this->element = self::$maxElement++;
   }
 
   /**
@@ -149,10 +149,16 @@ class PagerDefault extends SelectQueryEx
    * whatever reason you want to explicitly define an element for a given query,
    * you may do so here.
    *
+   * Setting the element here also increments the static $maxElement counter,
+   * which is used for determining the $element when there's none specified.
+   *
    * @param $element
    */
   public function element($element) {
     $this->element = $element;
+    if ($element >= self::$maxElement) {
+      self::$maxElement = ++$element;
+    }
     return $this;
   }
 }
