| @@ 300-333 (lines=34) @@ | ||
| 297 | /** |
|
| 298 | * {@inheritdoc} |
|
| 299 | */ |
|
| 300 | public function getColumns($tableName) |
|
| 301 | { |
|
| 302 | $columns = []; |
|
| 303 | $sql = sprintf( |
|
| 304 | "SELECT column_name, data_type, is_identity, is_nullable, |
|
| 305 | column_default, character_maximum_length, numeric_precision, numeric_scale |
|
| 306 | FROM information_schema.columns |
|
| 307 | WHERE table_name ='%s'", |
|
| 308 | $tableName |
|
| 309 | ); |
|
| 310 | $columnsInfo = $this->fetchAll($sql); |
|
| 311 | ||
| 312 | foreach ($columnsInfo as $columnInfo) { |
|
| 313 | $column = new Column(); |
|
| 314 | $column->setName($columnInfo['column_name']) |
|
| 315 | ->setType($this->getPhinxType($columnInfo['data_type'])) |
|
| 316 | ->setNull($columnInfo['is_nullable'] === 'YES') |
|
| 317 | ->setDefault($columnInfo['column_default']) |
|
| 318 | ->setIdentity($columnInfo['is_identity'] === 'YES') |
|
| 319 | ->setPrecision($columnInfo['numeric_precision']) |
|
| 320 | ->setScale($columnInfo['numeric_scale']); |
|
| 321 | ||
| 322 | if (preg_match('/\bwith time zone$/', $columnInfo['data_type'])) { |
|
| 323 | $column->setTimezone(true); |
|
| 324 | } |
|
| 325 | ||
| 326 | if (isset($columnInfo['character_maximum_length'])) { |
|
| 327 | $column->setLimit($columnInfo['character_maximum_length']); |
|
| 328 | } |
|
| 329 | $columns[] = $column; |
|
| 330 | } |
|
| 331 | ||
| 332 | return $columns; |
|
| 333 | } |
|
| 334 | ||
| 335 | /** |
|
| 336 | * {@inheritdoc} |
|
| @@ 354-381 (lines=28) @@ | ||
| 351 | /** |
|
| 352 | * {@inheritdoc} |
|
| 353 | */ |
|
| 354 | public function getColumns($tableName) |
|
| 355 | { |
|
| 356 | $columns = []; |
|
| 357 | $rows = $this->fetchAll(sprintf('SHOW COLUMNS FROM %s', $this->quoteTableName($tableName))); |
|
| 358 | foreach ($rows as $columnInfo) { |
|
| 359 | $phinxType = $this->getPhinxType($columnInfo['Type']); |
|
| 360 | ||
| 361 | $column = new Column(); |
|
| 362 | $column->setName($columnInfo['Field']) |
|
| 363 | ->setNull($columnInfo['Null'] !== 'NO') |
|
| 364 | ->setDefault($columnInfo['Default']) |
|
| 365 | ->setType($phinxType['name']) |
|
| 366 | ->setSigned(strpos($columnInfo['Type'], 'unsigned') === false) |
|
| 367 | ->setLimit($phinxType['limit']); |
|
| 368 | ||
| 369 | if ($columnInfo['Extra'] === 'auto_increment') { |
|
| 370 | $column->setIdentity(true); |
|
| 371 | } |
|
| 372 | ||
| 373 | if (isset($phinxType['values'])) { |
|
| 374 | $column->setValues($phinxType['values']); |
|
| 375 | } |
|
| 376 | ||
| 377 | $columns[] = $column; |
|
| 378 | } |
|
| 379 | ||
| 380 | return $columns; |
|
| 381 | } |
|
| 382 | ||
| 383 | /** |
|
| 384 | * {@inheritdoc} |
|