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);
}
$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();
}
$this->information .= '<b>sql error:</b> ' . StringUtil::encodeHTML($this->getErrorDesc()) . '<br />';
$this->information .= '<b>sql error number:</b> ' . StringUtil::encodeHTML($this->getErrorNumber()) . '<br />';
$this->information .= '<b>sql version:</b> ' . StringUtil::encodeHTML($this->getSQLVersion()) . '<br />';
+ if ($this->preparedStatement !== null) $this->information .= '<b>sql query:</b> ' . StringUtil::encodeHTML($this->preparedStatement->getSQLQuery()) . '<br />';
$this->information .= "\n<!-- db error: #".$this->db->getErrorNumber().': '.$this->db->getErrorDesc()." -->\n";
if ($this->preparedStatement !== null) {
*/
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;
}
/**
}
return '';
}
+
+ /**
+ * Returns the SQL query of this statement.
+ *
+ * @return string
+ */
+ public function getSQLQuery() {
+ return $this->query;
+ }
}