From: Jan Schneider Date: Wed, 22 Dec 2010 22:49:39 +0000 (+0100) Subject: Add last_query property. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=04ac6d67ebd338d6b884fb8eccb8dfd9c75e2f8e;p=horde.git Add last_query property. --- diff --git a/framework/Db/lib/Horde/Db/Adapter/Base.php b/framework/Db/lib/Horde/Db/Adapter/Base.php index abe1f1c5a..f16b0fd21 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Base.php +++ b/framework/Db/lib/Horde/Db/Adapter/Base.php @@ -24,6 +24,13 @@ 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()); diff --git a/framework/Db/lib/Horde/Db/Adapter/Mysql.php b/framework/Db/lib/Horde/Db/Adapter/Mysql.php index 97e22fdb9..e09905298 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Mysql.php +++ b/framework/Db/lib/Horde/Db/Adapter/Mysql.php @@ -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; } diff --git a/framework/Db/lib/Horde/Db/Adapter/Mysqli.php b/framework/Db/lib/Horde/Db/Adapter/Mysqli.php index a838b1208..c883fbf98 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Mysqli.php +++ b/framework/Db/lib/Horde/Db/Adapter/Mysqli.php @@ -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); diff --git a/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php b/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php index 499956048..01a318409 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php +++ b/framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php @@ -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'); } diff --git a/framework/Db/lib/Horde/Db/Adapter/Pdo/Pgsql.php b/framework/Db/lib/Horde/Db/Adapter/Pdo/Pgsql.php index ff741a4b5..8d306f370 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Pdo/Pgsql.php +++ b/framework/Db/lib/Horde/Db/Adapter/Pdo/Pgsql.php @@ -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']); diff --git a/framework/Db/lib/Horde/Db/Adapter/Pdo/Sqlite.php b/framework/Db/lib/Horde/Db/Adapter/Pdo/Sqlite.php index 3dd66b26d..2c91854af 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Pdo/Sqlite.php +++ b/framework/Db/lib/Horde/Db/Adapter/Pdo/Sqlite.php @@ -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(*)'); }