From: Alexander Ebert Date: Thu, 15 Dec 2011 15:22:39 +0000 (+0100) Subject: Enhanced database exceptions X-Git-Tag: 2.0.0_Beta_1~1517 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=583e566a2a6aa56aaa464a5196f3ae9a227dcc8f;p=GitHub%2FWoltLab%2FWCF.git Enhanced database exceptions --- 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; + } }