githubtrue/backend/vendor/illuminate/database/QueryException.php @ cb15593b
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Illuminate\Database; |
4 |
|
5 |
use PDOException; |
6 |
|
7 |
class QueryException extends PDOException |
8 |
{
|
9 |
/**
|
10 |
* The SQL for the query.
|
11 |
*
|
12 |
* @var string
|
13 |
*/
|
14 |
protected $sql; |
15 |
|
16 |
/**
|
17 |
* The bindings for the query.
|
18 |
*
|
19 |
* @var array
|
20 |
*/
|
21 |
protected $bindings; |
22 |
|
23 |
/**
|
24 |
* Create a new query exception instance.
|
25 |
*
|
26 |
* @param string $sql
|
27 |
* @param array $bindings
|
28 |
* @param \Exception $previous
|
29 |
* @return void
|
30 |
*/
|
31 |
public function __construct($sql, array $bindings, $previous) |
32 |
{
|
33 |
parent::__construct('', 0, $previous); |
34 |
|
35 |
$this->sql = $sql; |
36 |
$this->bindings = $bindings; |
37 |
$this->previous = $previous; |
38 |
$this->code = $previous->getCode(); |
39 |
$this->message = $this->formatMessage($sql, $bindings, $previous); |
40 |
|
41 |
if ($previous instanceof PDOException) { |
42 |
$this->errorInfo = $previous->errorInfo; |
43 |
}
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
* Format the SQL error message.
|
48 |
*
|
49 |
* @param string $sql
|
50 |
* @param array $bindings
|
51 |
* @param \Exception $previous
|
52 |
* @return string
|
53 |
*/
|
54 |
protected function formatMessage($sql, $bindings, $previous) |
55 |
{
|
56 |
return $previous->getMessage().' (SQL: '.str_replace_array('\?', $bindings, $sql).')'; |
57 |
}
|
58 |
|
59 |
/**
|
60 |
* Get the SQL for the query.
|
61 |
*
|
62 |
* @return string
|
63 |
*/
|
64 |
public function getSql() |
65 |
{
|
66 |
return $this->sql; |
67 |
}
|
68 |
|
69 |
/**
|
70 |
* Get the bindings for the query.
|
71 |
*
|
72 |
* @return array
|
73 |
*/
|
74 |
public function getBindings() |
75 |
{
|
76 |
return $this->bindings; |
77 |
}
|
78 |
}
|