Add last_query property.
authorJan Schneider <jan@horde.org>
Wed, 22 Dec 2010 22:49:39 +0000 (23:49 +0100)
committerJan Schneider <jan@horde.org>
Wed, 22 Dec 2010 22:50:02 +0000 (23:50 +0100)
framework/Db/lib/Horde/Db/Adapter/Base.php
framework/Db/lib/Horde/Db/Adapter/Mysql.php
framework/Db/lib/Horde/Db/Adapter/Mysqli.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Pgsql.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Sqlite.php

index abe1f1c..f16b0fd 100644 (file)
 abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
 {
     /**
+     * The last query sent to the database.
+     *
+     * @var string
+     */
+    public $last_query;
+
+    /**
      * Config options.
      *
      * @var array
@@ -521,6 +528,7 @@ abstract class Horde_Db_Adapter_Base implements Horde_Db_Adapter
         $t->push();
 
         try {
+            $this->last_query = $sql;
             $stmt = $this->_connection->query($sql);
         } catch (Exception $e) {
             $this->_logError($sql, 'QUERY FAILED: ' . $e->getMessage());
index 97e22fd..e099052 100644 (file)
@@ -244,6 +244,7 @@ class Horde_Db_Adapter_Mysql extends Horde_Db_Adapter_Base
         $t = new Horde_Support_Timer();
         $t->push();
 
+        $this->last_query = $sql;
         $stmt = mysql_query($sql, $this->_connection);
         if (!$stmt) {
             $this->_logInfo($sql, 'QUERY FAILED: ' . mysql_error($this->_connection));
@@ -281,6 +282,7 @@ class Horde_Db_Adapter_Mysql extends Horde_Db_Adapter_Base
     public function beginDbTransaction()
     {
         $this->_transactionStarted = true;
+        $this->last_query = 'SET AUTOCOMMIT=0; BEGIN';
         @mysql_query('SET AUTOCOMMIT=0', $this->_connection) && @mysql_query('BEGIN', $this->_connection);
     }
 
@@ -289,6 +291,7 @@ class Horde_Db_Adapter_Mysql extends Horde_Db_Adapter_Base
      */
     public function commitDbTransaction()
     {
+        $this->last_query = 'COMMIT; SET AUTOCOMMIT=1';
         @mysql_query('COMMIT', $this->_connection) && @mysql_query('SET AUTOCOMMIT=1', $this->_connection);
         $this->_transactionStarted = false;
     }
@@ -299,8 +302,11 @@ class Horde_Db_Adapter_Mysql extends Horde_Db_Adapter_Base
      */
     public function rollbackDbTransaction()
     {
-        if (! $this->_transactionStarted) { return; }
+        if (!$this->_transactionStarted) {
+            return;
+        }
 
+        $this->last_query = 'ROLLBACK; SET AUTOCOMMIT=1';
         @mysql_query('ROLLBACK', $this->_connection) && @mysql_query('SET AUTOCOMMIT=1', $this->_connection);
         $this->_transactionStarted = false;
     }
index a838b12..c883fbf 100644 (file)
@@ -167,6 +167,7 @@ class Horde_Db_Adapter_Mysqli extends Horde_Db_Adapter_Base
      */
     public function isActive()
     {
+        $this->last_query = 'SELECT 1';
         return isset($this->_connection) && $this->_connection->query('SELECT 1');
     }
 
@@ -298,6 +299,7 @@ class Horde_Db_Adapter_Mysqli extends Horde_Db_Adapter_Base
         $t = new Horde_Support_Timer();
         $t->push();
 
+        $this->last_query = $sql;
         $stmt = $this->_connection->query($sql);
         if (!$stmt) {
             $this->_logInfo($sql, 'QUERY FAILED: ' . $this->_connection->error);
index 4999560..01a3184 100644 (file)
@@ -60,6 +60,7 @@ abstract class Horde_Db_Adapter_Pdo_Base extends Horde_Db_Adapter_Base
      */
     public function isActive()
     {
+        $this->last_query = 'SELECT 1';
         return isset($this->_connection) &&
                $this->_connection->query('SELECT 1');
     }
index ff741a4..8d306f3 100644 (file)
@@ -87,6 +87,7 @@ class Horde_Db_Adapter_Pdo_Pgsql extends Horde_Db_Adapter_Pdo_Base
 
         parent::connect();
 
+        $this->last_query = "SET datestyle TO 'iso'";
         $retval = $this->_connection->exec("SET datestyle TO 'iso'");
         if ($retval === false) {
             $error = $this->_connection->errorInfo();
@@ -196,7 +197,8 @@ class Horde_Db_Adapter_Pdo_Pgsql extends Horde_Db_Adapter_Pdo_Base
     protected function _configureConnection()
     {
         if (!empty($this->_config['encoding'])) {
-            $this->_connection->execute('SET client_encoding TO '.$this->quoteString($this->_config['encoding']));
+            $this->last_query = 'SET client_encoding TO '.$this->quoteString($this->_config['encoding']);
+            $this->_connection->execute($this->last_query);
         }
 
         if (!empty($this->_config['client_min_messages'])) $this->setClientMinMessages($this->_config['client_min_messages']);
index 3dd66b2..2c91854 100644 (file)
@@ -88,18 +88,21 @@ class Horde_Db_Adapter_Pdo_Sqlite extends Horde_Db_Adapter_Pdo_Base
 
         $this->_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
 
+        $this->last_query = 'PRAGMA full_column_names=0';
         $retval = $this->_connection->exec('PRAGMA full_column_names=0');
         if ($retval === false) {
             $error = $this->_connection->errorInfo();
             throw new Horde_Db_Exception($error[2]);
         }
 
+        $this->last_query = 'PRAGMA short_column_names=1';
         $retval = $this->_connection->exec('PRAGMA short_column_names=1');
         if ($retval === false) {
             $error = $this->_connection->errorInfo();
             throw new Horde_Db_Exception($error[2]);
         }
 
+        $this->last_query = 'SELECT sqlite_version(*)';
         $this->_sqliteVersion = $this->selectValue('SELECT sqlite_version(*)');
     }