Skip to content

Commit

Permalink
Support MySQL error codes in DB exceptions (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkeung authored and andrerom committed Oct 17, 2017
1 parent e806087 commit 7d92d36
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions kernel/private/classes/exceptions/database/exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,30 @@
*/
class eZDBException extends ezcBaseException
{
/**
* Original message, before escaping
*/
public $originalMessage;

/**
* Constructs a new eZDBException with $message and $code
*
* @param string $message
* @param int $code
*/
public function __construct( $message, $code = 0 )
{
$this->originalMessage = $message;
$this->code = $code;

if ( php_sapi_name() == 'cli' )
{
$this->message = $message;
}
else
{
$this->message = htmlspecialchars( $message, ENT_QUOTES, 'UTF-8' );
}
}
}
?>
3 changes: 2 additions & 1 deletion lib/ezdb/classes/ezmysqlidb.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ function query( $sql, $server = false )
}
else
{
$errorMessage = 'Query error (' . mysqli_errno( $connection ) . '): ' . mysqli_error( $connection ) . '. Query: ' . $sql;
$this->setError();
$errorMessage = 'Query error (' . $this->ErrorNumber . '): ' . $this->ErrorMessage . '. Query: ' . $sql;
eZDebug::writeError( $errorMessage, __CLASS__ );
$oldRecordError = $this->RecordError;
// Turn off error handling while we unlock
Expand Down

0 comments on commit 7d92d36

Please sign in to comment.