From 754092bc625a5eb3e70777b1e8edd6d07eb23f97 Mon Sep 17 00:00:00 2001
From: James Sansbury <james.sansbury@lullabot.com>
Date: Thu, 25 Aug 2011 10:59:39 -0400
Subject: [PATCH] Issue #802514 by douggreen, q0rban: Allow hook_query_alter()
 implementations to alter the connection.

---
 includes/database/query.inc  |   18 ++++++++++++++++++
 includes/database/select.inc |    4 ++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/includes/database/query.inc b/includes/database/query.inc
index c7363f2..fbef01f 100644
--- a/includes/database/query.inc
+++ b/includes/database/query.inc
@@ -239,6 +239,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();
 }
 
 /**
@@ -388,6 +396,16 @@ abstract class Query implements QueryPlaceholderInterface {
   }
 
   /**
+   * 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() {
+    return $this->connection;
+  }
+
+  /**
    * Adds a comment to the query.
    *
    * By adding a comment to a query, you can more easily find it in your
diff --git a/includes/database/select.inc b/includes/database/select.inc
index 7504778..a8fc256 100644
--- a/includes/database/select.inc
+++ b/includes/database/select.inc
@@ -580,6 +580,10 @@ class SelectQueryExtender implements SelectQueryInterface {
 
   /* Implementations of QueryAlterableInterface. */
 
+  public function &connection() {
+    return $this->connection;
+  }
+
   public function addTag($tag) {
     $this->query->addTag($tag);
     return $this;
-- 
1.7.5.4

