コード例 #1
0
ファイル: MysqlAdapter.php プロジェクト: alprs/phinx
 /**
  * {@inheritdoc}
  */
 public function getColumns($tableName)
 {
     $columns = array();
     $rows = $this->fetchAll(sprintf('SHOW COLUMNS FROM %s', $tableName));
     foreach ($rows as $columnInfo) {
         $column = new Column();
         $column->setName($columnInfo['Field'])->setType($columnInfo['Type'])->setNull($columnInfo['Null'] != 'NO')->setDefault($columnInfo['Default']);
         $phinxType = $this->getPhinxType($columnInfo['Type']);
         $column->setType($phinxType['name'])->setLimit($phinxType['limit']);
         if ($columnInfo['Extra'] == 'auto_increment') {
             $column->setIdentity(true);
         }
         $columns[] = $column;
     }
     return $columns;
 }
コード例 #2
0
ファイル: SQLiteAdapter.php プロジェクト: elliotwms/phinx
 /**
  * {@inheritdoc}
  */
 public function getColumns($tableName)
 {
     $columns = array();
     $rows = $this->fetchAll(sprintf('pragma table_info(%s)', $this->quoteTableName($tableName)));
     foreach ($rows as $columnInfo) {
         $column = new Column();
         $type = strtolower($columnInfo['type']);
         $column->setName($columnInfo['name'])->setNull($columnInfo['notnull'] != '1')->setDefault($columnInfo['dflt_value']);
         $phinxType = $this->getPhinxType($type);
         $column->setType($phinxType['name'])->setLimit($phinxType['limit']);
         if ($columnInfo['pk'] == 1) {
             $column->setIdentity(true);
         }
         $columns[] = $column;
     }
     return $columns;
 }
コード例 #3
0
ファイル: Table.php プロジェクト: stephenorr/phinx
 /**
  * Change a table column type.
  *
  * @param string        $columnName    Column Name
  * @param string|Column $newColumnType New Column Type
  * @param array         $options       Options
  * @return Table
  */
 public function changeColumn($columnName, $newColumnType, $options = array())
 {
     // create a column object if one wasn't supplied
     if (!$newColumnType instanceof Column) {
         $newColumn = new Column();
         $newColumn->setType($newColumnType);
         $newColumn->setOptions($options);
     } else {
         $newColumn = $newColumnType;
     }
     // if the name was omitted use the existing column name
     if (null === $newColumn->getName() || strlen($newColumn->getName()) === 0) {
         $newColumn->setName($columnName);
     }
     $this->getAdapter()->changeColumn($this->getName(), $columnName, $newColumn);
     return $this;
 }
コード例 #4
0
 /**
  * Sets the column dbType.
  *
  * @param string $type
  *
  * @return $this
  */
 public function setType($type)
 {
     $this->column->setType($type);
     return $this;
 }