sql/src/QueryError.php

35 lines
740 B
PHP
Raw Permalink Normal View History

2018-06-26 13:14:24 +02:00
<?php
namespace Amp\Sql;
2018-06-29 12:15:39 +02:00
class QueryError extends \Error
{
2018-06-26 13:14:24 +02:00
protected $query = "";
2018-06-29 12:15:39 +02:00
public function __construct(string $message, string $query = "", \Throwable $previous = null)
{
2018-06-29 19:24:35 +02:00
if ($query !== "") {
2018-06-26 13:14:24 +02:00
$this->query = $query;
}
parent::__construct($message, 0, $previous);
}
2018-06-29 12:15:39 +02:00
final public function getQuery(): string
{
2018-06-26 13:14:24 +02:00
return $this->query;
}
2018-06-29 12:15:39 +02:00
public function __toString(): string
{
2018-06-29 19:24:57 +02:00
if ($this->query === "") {
2018-06-26 13:14:24 +02:00
return parent::__toString();
}
$msg = $this->message;
$this->message .= "\nCurrent query was {$this->query}";
$str = parent::__toString();
$this->message = $msg;
return $str;
}
}