From: Marcel Werk Date: Sun, 23 Oct 2011 21:52:25 +0000 (+0200) Subject: Added original sql query to database exception output X-Git-Tag: 2.0.0_Beta_1~1664 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=63613e730bd71b78486e6e82ff0f1e7ea0474935;p=GitHub%2FWoltLab%2FWCF.git Added original sql query to database exception output --- diff --git a/wcfsetup/install/files/lib/system/database/Database.class.php b/wcfsetup/install/files/lib/system/database/Database.class.php index b99be3abe1..e5fc098217 100644 --- a/wcfsetup/install/files/lib/system/database/Database.class.php +++ b/wcfsetup/install/files/lib/system/database/Database.class.php @@ -186,7 +186,7 @@ abstract class Database { try { $pdoStatement = $this->pdo->prepare($statement); if ($pdoStatement instanceof \PDOStatement) { - return new $this->preparedStatementClassName($this, $pdoStatement); + return new $this->preparedStatementClassName($this, $pdoStatement, $statement); } throw new DatabaseException("Can not prepare statement: ".$statement, $this); } diff --git a/wcfsetup/install/files/lib/system/database/DatabaseException.class.php b/wcfsetup/install/files/lib/system/database/DatabaseException.class.php index aac5227374..9cf8bd604e 100644 --- a/wcfsetup/install/files/lib/system/database/DatabaseException.class.php +++ b/wcfsetup/install/files/lib/system/database/DatabaseException.class.php @@ -64,7 +64,7 @@ class DatabaseException extends SystemException { $this->preparedStatement = $preparedStatement; // prefer errors from prepared statement - if (($this->preparedStatement instanceof PreparedStatement) && $this->preparedStatement->getErrorNumber()) { + if ($this->preparedStatement !== null && $this->preparedStatement->getErrorNumber()) { $this->errorNumber = $this->preparedStatement->getErrorNumber(); $this->errorDesc = $this->preparedStatement->getErrorDesc(); } @@ -129,6 +129,7 @@ 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) { 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 432b18fa3d..4a18ffa8d0 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -29,15 +29,23 @@ class PreparedStatement { */ protected $pdoStatement = null; + /** + * SQL query + * @var string + */ + protected $query = ''; + /** * Creates a new PreparedStatement object. * * @param wcf\system\database\Database $database * @param \PDOStatement $pdoStatement + * @param string $query SQL query */ - public function __construct(Database $database, \PDOStatement $pdoStatement) { + public function __construct(Database $database, \PDOStatement $pdoStatement, $query = '') { $this->database = $database; $this->pdoStatement = $pdoStatement; + $this->query = $query; } /** @@ -157,4 +165,13 @@ class PreparedStatement { } return ''; } + + /** + * Returns the SQL query of this statement. + * + * @return string + */ + public function getSQLQuery() { + return $this->query; + } }