From 583e566a2a6aa56aaa464a5196f3ae9a227dcc8f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 15 Dec 2011 16:22:39 +0100 Subject: [PATCH] Enhanced database exceptions --- .../system/database/DatabaseException.class.php | 11 +++++++---- .../statement/PreparedStatement.class.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/database/DatabaseException.class.php b/wcfsetup/install/files/lib/system/database/DatabaseException.class.php index 9cf8bd604e..0630af8585 100644 --- a/wcfsetup/install/files/lib/system/database/DatabaseException.class.php +++ b/wcfsetup/install/files/lib/system/database/DatabaseException.class.php @@ -129,11 +129,14 @@ class DatabaseException extends SystemException { $this->information .= 'sql error: ' . StringUtil::encodeHTML($this->getErrorDesc()) . '
'; $this->information .= 'sql error number: ' . StringUtil::encodeHTML($this->getErrorNumber()) . '
'; $this->information .= 'sql version: ' . StringUtil::encodeHTML($this->getSQLVersion()) . '
'; - if ($this->preparedStatement !== null) $this->information .= 'sql query: ' . StringUtil::encodeHTML($this->preparedStatement->getSQLQuery()) . '
'; - - $this->information .= "\n\n"; if ($this->preparedStatement !== null) { - $this->information .= "\n\n"; + $this->information .= 'sql query: ' . StringUtil::encodeHTML($this->preparedStatement->getSQLQuery()) . '
'; + $parameters = $this->preparedStatement->getSQLParameters(); + if (!empty($parameters)) { + foreach ($parameters as $index => $parameter) { + $this->information .= 'sql query parameter ' . $index . ':' . StringUtil::encodeHTML($parameter) . '
'; + } + } } parent::show(); diff --git a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php index 5421e29385..1bc7265db7 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -24,6 +24,12 @@ class PreparedStatement { */ protected $database = null; + /** + * SQL query parameters + * @var array + */ + protected $parameters = array(); + /** * pdo statement object * @@ -76,6 +82,7 @@ class PreparedStatement { * @param array $parameters */ public function execute(array $parameters = array()) { + $this->parameters = $parameters; $this->database->incrementQueryCount(); $this->database->beginTransaction(); @@ -101,6 +108,7 @@ class PreparedStatement { * @param array $parameters */ public function executeUnbuffered(array $parameters = array()) { + $this->parameters = $parameters; $this->database->incrementQueryCount(); try { @@ -204,4 +212,13 @@ class PreparedStatement { public function getSQLQuery() { return $this->query; } + + /** + * Returns the SQL query parameters of this statement. + * + * @return array + */ + public function getSQLParameters() { + return $this->parameters; + } } -- 2.20.1