1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Doctrine\DBAL\Driver; |
5
|
|
|
|
6
|
|
|
use Doctrine\DBAL\ParameterType; |
7
|
|
|
use PDO; |
8
|
|
|
use function assert; |
9
|
|
|
use function func_get_args; |
10
|
|
|
|
11
|
|
|
final class WrappedPDOConnection implements Connection, ServerInfoAwareConnection |
12
|
|
|
{ |
13
|
|
|
/** @var PDO */ |
14
|
|
|
private $connection; |
15
|
|
|
|
16
|
405 |
|
private function __construct(PDO $connection) |
17
|
|
|
{ |
18
|
405 |
|
$this->connection = $connection; |
19
|
405 |
|
} |
20
|
|
|
|
21
|
405 |
|
public static function fromInstance(PDO $connection) : self |
22
|
|
|
{ |
23
|
|
|
try { |
24
|
405 |
|
$connection->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]); |
25
|
405 |
|
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
26
|
|
|
|
27
|
405 |
|
return new self($connection); |
28
|
|
|
} catch (\PDOException $exception) { |
29
|
|
|
throw new PDOException($exception); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function setAttribute(int $attribute, $value) : bool |
34
|
|
|
{ |
35
|
|
|
return $this->connection->setAttribute($attribute, $value); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
310 |
|
public function prepare($prepareString) |
42
|
|
|
{ |
43
|
|
|
try { |
44
|
310 |
|
$stmt = $this->connection->prepare($prepareString); |
45
|
310 |
|
assert($stmt instanceof PDOStatement); |
46
|
|
|
|
47
|
310 |
|
return $stmt; |
48
|
|
|
} catch (\PDOException $exception) { |
49
|
|
|
throw new PDOException($exception); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
81 |
|
public function query() |
57
|
|
|
{ |
58
|
81 |
|
$args = func_get_args(); |
59
|
|
|
|
60
|
|
|
try { |
61
|
81 |
|
$stmt = $this->connection->query(...$args); |
|
|
|
|
62
|
81 |
|
assert($stmt instanceof PDOStatement); |
63
|
|
|
|
64
|
81 |
|
return $stmt; |
65
|
|
|
} catch (\PDOException $exception) { |
66
|
|
|
throw new PDOException($exception); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function quote($input, $type = ParameterType::STRING) |
74
|
|
|
{ |
75
|
|
|
return $this->connection->quote($input, $type); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
202 |
|
public function exec($statement) |
82
|
|
|
{ |
83
|
|
|
try { |
84
|
202 |
|
return $this->connection->exec($statement); |
85
|
|
|
} catch (\PDOException $exception) { |
86
|
|
|
throw new PDOException($exception); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
52 |
|
public function lastInsertId($name = null) |
94
|
|
|
{ |
95
|
|
|
try { |
96
|
52 |
|
if ($name === null) { |
97
|
52 |
|
return $this->connection->lastInsertId(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->connection->lastInsertId($name); |
101
|
|
|
} catch (\PDOException $exception) { |
102
|
|
|
throw new PDOException($exception); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
27 |
|
public function beginTransaction() |
110
|
|
|
{ |
111
|
27 |
|
return $this->connection->beginTransaction(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function commit() |
118
|
|
|
{ |
119
|
|
|
return $this->connection->commit(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* {@inheritdoc} |
124
|
|
|
*/ |
125
|
27 |
|
public function rollBack() |
126
|
|
|
{ |
127
|
27 |
|
return $this->connection->rollBack(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* {@inheritdoc} |
132
|
|
|
*/ |
133
|
|
|
public function errorCode() |
134
|
|
|
{ |
135
|
|
|
return $this->connection->errorCode(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* {@inheritdoc} |
140
|
|
|
*/ |
141
|
|
|
public function errorInfo() |
142
|
|
|
{ |
143
|
|
|
return $this->connection->errorInfo(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
*/ |
149
|
|
|
public function getServerVersion() |
150
|
|
|
{ |
151
|
|
|
return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* {@inheritdoc} |
156
|
|
|
*/ |
157
|
|
|
public function requiresQueryForServerVersion() |
158
|
|
|
{ |
159
|
|
|
return false; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|