| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Framework\Database\Exceptions; |
| 4 |
|
| 5 |
use Give\Framework\Exceptions\Primitives\Exception; |
| 6 |
use Throwable; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class DatabaseQueryException |
| 10 |
* |
| 11 |
* An exception for when errors occurred within the database while performing a query, which stores the SQL errors the |
| 12 |
* database returned |
| 13 |
* |
| 14 |
* @since 2.21.0 Use the GiveWP exception class |
| 15 |
* @since 2.9.2 |
| 16 |
*/ |
| 17 |
class DatabaseQueryException extends Exception |
| 18 |
{ |
| 19 |
/** |
| 20 |
* @var string[] |
| 21 |
*/ |
| 22 |
private $queryErrors; |
| 23 |
|
| 24 |
/** |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
private $query; |
| 28 |
|
| 29 |
/** |
| 30 |
* @since 2.21.0 include query and query errors, and make auto-logging compatible |
| 31 |
* @since 2.9.2 |
| 32 |
*/ |
| 33 |
public function __construct( |
| 34 |
string $query, |
| 35 |
array $queryErrors, |
| 36 |
string $message = 'Database Query', |
| 37 |
$code = 0, |
| 38 |
Throwable $previous = null |
| 39 |
) { |
| 40 |
$this->query = $query; |
| 41 |
$this->queryErrors = $queryErrors; |
| 42 |
|
| 43 |
parent::__construct($message, $code, $previous); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the query errors |
| 48 |
* |
| 49 |
* @since 2.9.2 |
| 50 |
* |
| 51 |
* @return string[] |
| 52 |
*/ |
| 53 |
public function getQueryErrors(): array |
| 54 |
{ |
| 55 |
return $this->queryErrors; |
| 56 |
} |
| 57 |
|
| 58 |
public function getQuery(): string |
| 59 |
{ |
| 60 |
return $this->query; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* @inheritDoc |
| 65 |
*/ |
| 66 |
public function getLogContext(): array |
| 67 |
{ |
| 68 |
return [ |
| 69 |
'category' => 'Uncaught database exception', |
| 70 |
'Query' => $this->query, |
| 71 |
'Query Errors' => $this->queryErrors, |
| 72 |
]; |
| 73 |
} |
| 74 |
} |
| 75 |
|