1 | <?php |
||
41 | abstract class PdoAdapter extends AbstractAdapter |
||
42 | { |
||
43 | /** |
||
44 | * @var \PDO|null |
||
45 | */ |
||
46 | protected $connection; |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 287 | public function setOptions(array $options) |
|
61 | |||
62 | /** |
||
63 | * Sets the database connection. |
||
64 | * |
||
65 | * @param \PDO $connection Connection |
||
66 | * @return AdapterInterface |
||
67 | */ |
||
68 | 193 | public function setConnection(\PDO $connection) |
|
95 | |||
96 | /** |
||
97 | * Gets the database connection |
||
98 | * |
||
99 | * @return \PDO |
||
100 | */ |
||
101 | 191 | public function getConnection() |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 1 | public function connect() |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function disconnect() |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | 218 | public function execute($sql) |
|
135 | |||
136 | /** |
||
137 | * Executes a query and returns PDOStatement. |
||
138 | * |
||
139 | * @param string $sql SQL |
||
140 | * @return \PDOStatement |
||
141 | */ |
||
142 | 220 | public function query($sql) |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 151 | public function fetchRow($sql) |
|
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | 213 | public function fetchAll($sql) |
|
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | 1 | public function insert(Table $table, $row) |
|
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | 11 | public function bulkinsert(Table $table, $rows) |
|
218 | |||
219 | /** |
||
220 | * {@inheritdoc} |
||
221 | */ |
||
222 | 5 | public function getVersions() |
|
228 | |||
229 | /** |
||
230 | * {@inheritdoc} |
||
231 | */ |
||
232 | 8 | public function getVersionLog() |
|
233 | { |
||
234 | 8 | $result = []; |
|
235 | |||
236 | 8 | switch ($this->options['version_order']) { |
|
237 | 8 | case \Phinx\Config\Config::VERSION_ORDER_CREATION_TIME: |
|
238 | 6 | $orderBy = 'version ASC'; |
|
239 | 6 | break; |
|
240 | 2 | case \Phinx\Config\Config::VERSION_ORDER_EXECUTION_TIME: |
|
241 | 1 | $orderBy = 'start_time ASC, version ASC'; |
|
242 | 1 | break; |
|
243 | 1 | default: |
|
244 | 1 | throw new \RuntimeException('Invalid version_order configuration option'); |
|
245 | 8 | } |
|
246 | |||
247 | 7 | $rows = $this->fetchAll(sprintf('SELECT * FROM %s ORDER BY %s', $this->getSchemaTableName(), $orderBy)); |
|
248 | 7 | foreach ($rows as $version) { |
|
249 | 7 | $result[$version['version']] = $version; |
|
250 | 7 | } |
|
251 | |||
252 | 7 | return $result; |
|
253 | } |
||
254 | |||
255 | /** |
||
256 | * {@inheritdoc} |
||
257 | */ |
||
258 | 5 | public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) |
|
292 | |||
293 | /** |
||
294 | * @inheritDoc |
||
295 | */ |
||
296 | 1 | public function toggleBreakpoint(MigrationInterface $migration) |
|
297 | { |
||
298 | 1 | $this->query( |
|
299 | 1 | sprintf( |
|
300 | 1 | 'UPDATE %1$s SET %2$s = CASE %2$s WHEN %3$s THEN %4$s ELSE %3$s END, %7$s = %7$s WHERE %5$s = \'%6$s\';', |
|
301 | 1 | $this->getSchemaTableName(), |
|
302 | 1 | $this->quoteColumnName('breakpoint'), |
|
303 | 1 | $this->castToBool(true), |
|
304 | 1 | $this->castToBool(false), |
|
305 | 1 | $this->quoteColumnName('version'), |
|
306 | 1 | $migration->getVersion(), |
|
307 | 1 | $this->quoteColumnName('start_time') |
|
308 | 1 | ) |
|
309 | 1 | ); |
|
310 | |||
311 | 1 | return $this; |
|
312 | } |
||
313 | |||
314 | /** |
||
315 | * @inheritDoc |
||
316 | */ |
||
317 | 1 | public function resetAllBreakpoints() |
|
318 | { |
||
319 | 1 | return $this->execute( |
|
320 | 1 | sprintf( |
|
321 | 1 | 'UPDATE %1$s SET %2$s = %3$s, %4$s = %4$s WHERE %2$s <> %3$s;', |
|
322 | 1 | $this->getSchemaTableName(), |
|
323 | 1 | $this->quoteColumnName('breakpoint'), |
|
324 | 1 | $this->castToBool(false), |
|
325 | 1 | $this->quoteColumnName('start_time') |
|
326 | 1 | ) |
|
327 | 1 | ); |
|
328 | } |
||
329 | |||
330 | /** |
||
331 | * {@inheritdoc} |
||
332 | */ |
||
333 | public function createSchema($schemaName = 'public') |
||
337 | |||
338 | /** |
||
339 | * {@inheritdoc} |
||
340 | */ |
||
341 | public function dropSchema($name) |
||
345 | |||
346 | /** |
||
347 | * {@inheritdoc} |
||
348 | */ |
||
349 | 208 | public function getColumnTypes() |
|
375 | |||
376 | /** |
||
377 | * {@inheritdoc} |
||
378 | */ |
||
379 | 121 | public function castToBool($value) |
|
380 | { |
||
381 | 121 | return (bool) $value ? 1 : 0; |
|
382 | } |
||
383 | |||
384 | /** |
||
385 | * Get the defintion for a `DEFAULT` statement. |
||
386 | * |
||
387 | * @param mixed $default |
||
388 | * @return string |
||
389 | */ |
||
390 | protected function getDefaultValueDefinition($default) |
||
399 | } |
||
400 |