1 | <?php |
||
20 | abstract class PDOConnection implements Connection, PDOExceptionMapper, Logger |
||
21 | { |
||
22 | /** |
||
23 | * @var PDO |
||
24 | */ |
||
25 | private $pdo; |
||
26 | |||
27 | /** |
||
28 | * @var TypeProvider |
||
29 | */ |
||
30 | private $types; |
||
31 | |||
32 | /** |
||
33 | * @var int number of nested calls to transact() |
||
34 | * |
||
35 | * @see transact() |
||
36 | */ |
||
37 | private $transaction_level = 0; |
||
38 | |||
39 | /** |
||
40 | * @var bool net result of nested calls to transact() |
||
41 | * |
||
42 | * @see transact() |
||
43 | */ |
||
44 | private $transaction_result; |
||
45 | |||
46 | /** |
||
47 | * @var Logger[] |
||
48 | */ |
||
49 | private $loggers = []; |
||
50 | |||
51 | /** |
||
52 | * To avoid duplicating dependencies, you should use DatabaseContainer::createPDOConnection() |
||
53 | * rather than calling this constructor directly. |
||
54 | * |
||
55 | * @param PDO $pdo |
||
56 | * @param TypeProvider $types |
||
57 | */ |
||
58 | 1 | public function __construct(PDO $pdo, TypeProvider $types) |
|
63 | |||
64 | /** |
||
65 | * @return PDO the internal PDO connection object |
||
66 | */ |
||
67 | public function getPDO() |
||
71 | |||
72 | /** |
||
73 | * @inheritdoc |
||
74 | */ |
||
75 | 1 | public function prepare(Statement $statement) |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | 1 | public function fetch(Statement $statement, $batch_size = 1000) |
|
106 | { |
||
107 | 1 | $mappers = $statement instanceof MapperProvider |
|
108 | 1 | ? $statement->getMappers() |
|
109 | 1 | : []; |
|
110 | |||
111 | 1 | return new Result( |
|
112 | 1 | $this->prepare($statement), |
|
113 | 1 | $batch_size, |
|
114 | 1 | $mappers |
|
115 | ); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @inheritdoc |
||
120 | */ |
||
121 | 1 | public function execute(Statement $statement) |
|
129 | |||
130 | /** |
||
131 | * @inheritdoc |
||
132 | */ |
||
133 | 1 | public function count(Countable $statement) |
|
137 | |||
138 | /** |
||
139 | * @inheritdoc |
||
140 | */ |
||
141 | 1 | public function transact(callable $func) |
|
188 | |||
189 | /** |
||
190 | * Internally expand SQL placeholders (for array-types) |
||
191 | * |
||
192 | * @param string $sql SQL with placeholders |
||
193 | * @param array $params placeholder name/value pairs |
||
194 | * |
||
195 | * @return string SQL with expanded placeholders |
||
196 | */ |
||
197 | 1 | private function expandPlaceholders($sql, array $params) |
|
217 | |||
218 | /** |
||
219 | * @param string|null $sequence_name auto-sequence name (or NULL for e.g. MySQL which supports only one auto-key) |
||
220 | * |
||
221 | * @return int|string |
||
222 | */ |
||
223 | public function lastInsertId($sequence_name = null) |
||
231 | |||
232 | /** |
||
233 | * @inheritdoc |
||
234 | */ |
||
235 | 1 | public function addLogger(Logger $logger) |
|
239 | |||
240 | /** |
||
241 | * @inheritdoc |
||
242 | */ |
||
243 | 1 | public function logQuery($sql, $params, $time_msec) |
|
249 | } |
||
250 |