2018-09-16 18:16:42 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Nominatim;
|
|
|
|
|
|
|
|
class DatabaseError extends \Exception
|
|
|
|
{
|
|
|
|
|
2019-02-24 18:14:36 +03:00
|
|
|
public function __construct($message, $code = 500, Exception $previous = null, $oPDOErr, $sSql = null)
|
2018-09-16 18:16:42 +03:00
|
|
|
{
|
|
|
|
parent::__construct($message, $code, $previous);
|
2019-02-24 18:14:36 +03:00
|
|
|
// https://secure.php.net/manual/en/class.pdoexception.php
|
|
|
|
$this->oPDOErr = $oPDOErr;
|
|
|
|
$this->sSql = $sSql;
|
2018-09-16 18:16:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSqlError()
|
|
|
|
{
|
2019-02-24 18:14:36 +03:00
|
|
|
return $this->oPDOErr->getMessage();
|
2018-09-16 18:16:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSqlDebugDump()
|
|
|
|
{
|
|
|
|
if (CONST_Debug) {
|
2019-02-24 18:14:36 +03:00
|
|
|
return var_export($this->oPDOErr, true);
|
2018-09-16 18:16:42 +03:00
|
|
|
} else {
|
2019-02-24 18:14:36 +03:00
|
|
|
return $this->sSql;
|
2018-09-16 18:16:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|