=== modified file 'includes/database/query.inc'
--- includes/database/query.inc	2010-03-09 05:01:45 +0000
+++ includes/database/query.inc	2010-05-19 00:06:26 +0000
@@ -197,6 +197,14 @@ interface QueryAlterableInterface {
    *   The previously attached metadata object, or NULL if one doesn't exist.
    */
   public function getMetaData($key);
+
+  /**
+   * Gets the current connection.
+   *
+   * This method returns by reference. That allows alter hooks to access the
+   * data structure directly and manipulate it before it gets compiled.
+   */
+  public function &connection();
 }
 
 /**

=== modified file 'includes/database/select.inc'
--- includes/database/select.inc	2010-02-17 05:24:53 +0000
+++ includes/database/select.inc	2010-05-19 00:06:26 +0000
@@ -491,6 +491,10 @@ class SelectQueryExtender implements Sel
 
   /* Implementations of QueryAlterableInterface. */
 
+  public function &connection() {
+    return $this->connection;
+  }
+
   public function addTag($tag) {
     $this->query->addTag($tag);
     return $this;
@@ -903,6 +907,10 @@ class SelectQuery extends Query implemen
     return isset($this->alterMetaData[$key]) ? $this->alterMetaData[$key] : NULL;
   }
 
+  public function &connection() {
+    return $this->connection;
+  }
+
   /* Implementations of QueryConditionInterface for the WHERE clause. */
 
   public function condition($field, $value = NULL, $operator = NULL) {

