Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $columnTypeMapper = new ColumnTypeMapper();
     $this->preExecute();
     $columns = $this->connection->query($this->getSql());
     if (empty($columns)) {
         throw new TableNotExistsException($this->tableName);
     }
     $table = new Table($this->tableName);
     if (null === $table->getSchema()) {
         $table->setSchema($columns[0]['table_schema']);
     }
     $columnCreator = new ColumnCreator();
     foreach ($columns as $column) {
         $columnType = $columnTypeMapper->getCommon($column['data_type']);
         $options = array();
         $options['not_null'] = $column['is_nullable'] === 'NO';
         $options['default'] = $column['column_default'];
         if ($columnType === 'string') {
             preg_match("/'(.*)'::character varying/", $column['column_default'], $matches);
             $options['default'] = isset($matches[1]) ? $matches[1] : '';
             $options['limit'] = $column['character_maximum_length'];
         }
         $column = $columnCreator->create($column['column_name'], $columnType, $options);
         $table->addColumn($column);
     }
     $this->loadConstraints($table);
     $this->postExecute();
     return $table;
 }
Пример #2
0
 public function testGetCommon()
 {
     $columnTypeMapper = new ColumnTypeMapper();
     $this->assertEquals('string', $columnTypeMapper->getCommon('character varying'));
     $this->assertEquals('text', $columnTypeMapper->getCommon('text'));
     $this->assertEquals('integer', $columnTypeMapper->getCommon('integer'));
     $this->assertEquals('biginteger', $columnTypeMapper->getCommon('bigint'));
     $this->assertEquals('smallinteger', $columnTypeMapper->getCommon('smallint'));
     $this->assertEquals('decimal', $columnTypeMapper->getCommon('decimal'));
     $this->assertEquals('float', $columnTypeMapper->getCommon('real'));
     $this->assertEquals('datetime', $columnTypeMapper->getCommon('timestamp'));
     $this->assertEquals('date', $columnTypeMapper->getCommon('date'));
     $this->assertEquals('time', $columnTypeMapper->getCommon('time'));
     $this->assertEquals('binary', $columnTypeMapper->getCommon('bytea'));
 }