2018-09-16 18:16:42 +03:00
|
|
|
<?php
|
2022-01-03 18:23:58 +03:00
|
|
|
/**
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
*
|
|
|
|
* This file is part of Nominatim. (https://nominatim.org)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 by the Nominatim developer community.
|
|
|
|
* For a full list of authors see the git log.
|
|
|
|
*/
|
2018-09-16 18:16:42 +03:00
|
|
|
|
|
|
|
namespace Nominatim;
|
|
|
|
|
|
|
|
class DatabaseError extends \Exception
|
|
|
|
{
|
|
|
|
|
2021-07-11 21:10:13 +03:00
|
|
|
public function __construct($message, $code, $previous, $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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|