Index: includes/pager.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/pager.inc,v
retrieving revision 1.86
diff -u -p -r1.86 pager.inc
--- includes/pager.inc	14 Nov 2010 22:07:57 -0000	1.86
+++ includes/pager.inc	17 Nov 2010 22:24:47 -0000
@@ -52,18 +52,15 @@ class PagerDefault extends SelectQueryEx
   }
 
   /**
-   * Override the execute method.
+   * Overrides the preExecute method.
    *
    * Before we run the query, we need to add pager-based range() instructions
    * to it.
    */
-  public function execute() {
-
-    // Add convenience tag to mark that this is an extended query. We have to
-    // do this in the constructor to ensure that it is set before preExecute()
-    // gets called.
-    if (!$this->preExecute($this)) {
-      return NULL;
+  public function preExecute(SelectQueryInterface $query = NULL) {
+    // If no query object is passed in, use $this.
+    if (!isset($query)) {
+      $query = $this;
     }
 
     // A NULL limit is the "kill switch" for pager queries.
@@ -76,7 +73,17 @@ class PagerDefault extends SelectQueryEx
     $current_page = pager_default_initialize($total_items, $this->limit, $this->element);
     $this->range($current_page * $this->limit, $this->limit);
 
-    // Now that we've added our pager-based range instructions, run the query normally.
+    return parent::preExecute($query);
+  }
+
+  /**
+   * Override the execute method.
+   */
+  public function execute() {
+    if (!$this->preExecute($this)) {
+      return NULL;
+    }
+
     return $this->query->execute();
   }
 
Index: includes/tablesort.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v
retrieving revision 1.60
diff -u -p -r1.60 tablesort.inc
--- includes/tablesort.inc	28 Oct 2010 02:27:08 -0000	1.60
+++ includes/tablesort.inc	17 Nov 2010 21:38:41 -0000
@@ -80,7 +80,7 @@ class TableSort extends SelectQueryExten
     // User has not specified a sort. Use default if specified; otherwise use "asc".
     else {
       foreach ($this->header as $header) {
-        if (isset($header['sort'])) {
+        if (isset($header['sort']) && is_array($header['sort'])) {
           return $header['sort'];
         }
       }
Index: includes/database/query.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/query.inc,v
retrieving revision 1.58
diff -u -p -r1.58 query.inc
--- includes/database/query.inc	26 Oct 2010 15:26:09 -0000	1.58
+++ includes/database/query.inc	17 Nov 2010 22:45:30 -0000
@@ -336,6 +336,26 @@ abstract class Query implements QueryPla
   public function &getComments() {
     return $this->comments;
   }
+
+  /**
+   * Outputs debugging information for the query.
+   *
+   * @return Query
+   *   The called object.
+   *
+   * @see debug()
+   */
+  public function debug($label = NULL, $print_r = FALSE) {
+    // Clone the current query object to not alter the actual.
+    $query = clone $this;
+    // Run pre-execution tasks and validation.
+    $query->preExecute();
+    $sql = strtr($query->connection->prefixTables($query), $query->getArguments());
+    debug($sql, $label, $print_r);
+    // Clean-up.
+    unset($query);
+    return $this;
+  }
 }
 
 /**
@@ -1478,6 +1498,30 @@ class MergeQuery extends Query implement
 }
 
 /**
+ * General class for an abstracted debug query running against dsm().
+ *
+ * Alternative approach. However, fixing preExecute() makes more sense.
+ */
+/*
+abstract class DebugQuery extends Query {
+  public function __construct($query, DatabaseConnection $connection) {
+    $options['return'] = Database::RETURN_AFFECTED;
+    parent::__construct($connection, $options);
+    $this->table = $table;
+  }
+
+  public function execute() {
+    // 1. Replace the database connection with DatabaseConnection_debug.
+
+    // 2. Make DatabaseConnection_debug connection a blackhole query against debug().
+
+    // 3. Execute the query as usual:
+    return $this->connection->query((string) $this, array(), $this->queryOptions);
+  }
+}
+*/
+
+/**
  * Generic class for a series of conditions in a query.
  */
 class DatabaseCondition implements QueryConditionInterface, Countable {
Index: includes/database/select.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database/select.inc,v
retrieving revision 1.52
diff -u -p -r1.52 select.inc
--- includes/database/select.inc	5 Oct 2010 01:42:24 -0000	1.52
+++ includes/database/select.inc	17 Nov 2010 22:43:20 -0000
@@ -686,6 +686,13 @@ class SelectQueryExtender implements Sel
       $query = $this;
     }
 
+    // Call preExecute() methods of all wrapping query extenders.
+    // @todo This is probably wrong. Last query extender is invoked twice.
+//    echo "<pre>"; var_dump(get_parent_class($this), get_class($this)); echo "</pre>\n";
+//    ddebug_backtrace();
+    if (method_exists($this, 'parent::preExecute')) {
+      return parent::preExecute($query);
+    }
     return $this->query->preExecute($query);
   }
 
@@ -840,6 +847,25 @@ class SelectQueryExtender implements Sel
       return $return;
     }
   }
+
+  /**
+   * Outputs debugging information for the query.
+   *
+   * @return Query
+   *   The called object.
+   *
+   * @see debug()
+   */
+  public function debug($label = NULL, $print_r = FALSE) {
+    // Clone the current query object to not alter the actual.
+    $query = clone $this;
+    // Run pre-execution tasks and validation.
+    $query->preExecute();
+    $query->query->debug($label, $print_r);
+    // Clean-up.
+    unset($query);
+    return $this;
+  }
 }
 
 /**
Index: modules/node/node.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.admin.inc,v
retrieving revision 1.101
diff -u -p -r1.101 node.admin.inc
--- modules/node/node.admin.inc	20 Oct 2010 01:31:07 -0000	1.101
+++ modules/node/node.admin.inc	17 Nov 2010 22:26:26 -0000
@@ -423,11 +423,15 @@ function node_admin_nodes() {
   }
   $nids = $query
     ->fields('n',array('nid'))
-    ->limit(50)
+    ->limit(2)
     ->orderByHeader($header)
-    ->execute()
-    ->fetchCol();
-  $nodes = node_load_multiple($nids);
+    ->debug();
+//  dpq($query);
+//  $nids = $query
+//    ->execute()
+//    ->fetchCol();
+//  $nodes = node_load_multiple($nids);
+  $nodes = array();
 
   // Prepare the list of nodes.
   $languages = language_list();
@@ -519,7 +523,9 @@ function node_admin_nodes() {
     );
   }
 
-  $form['pager'] = array('#markup' => theme('pager'));
+  $form['pager'] = array(
+    '#theme' => 'pager',
+  );
   return $form;
 }
 
