Exemplo n.º 1
0
 /**
  * カラム情報を取得する
  *
  * @param  string $table_name
  * @return Column[]
  */
 public function getColumns($table_name)
 {
     $sql = sprintf('SHOW COLUMNS FROM %s', $this->quoteTableName($table_name));
     $results = $this->db->build($sql)->fetchAll();
     $columns = [];
     foreach ($results as $result) {
         preg_match('/^.*\\(([0-9]+)\\)/', $result->Type, $matches);
         $limit = isset($matches[1]) ? $matches[1] : null;
         $column = new Column();
         $column->setName($result->Field)->setType($result->Type)->setNull($result->Null === 'YES')->setDefault($result->Default)->setLimit($limit);
         if ($result->Extra == 'auto_increment') {
             $result->setIdentity(true);
         }
         $columns[] = $column;
     }
     return $columns;
 }
Exemplo n.º 2
0
 /**
  * カラム情報を変更する
  *
  * @param  string $column_name
  * @param  string $column_type
  * @param  array $options
  * @return Table
  */
 public function changeColumn($column_name, $column_type, $options = [])
 {
     $column = new Column();
     $column->setName($column_name);
     $column->setType($column_type);
     $column->setOptions($options);
     $this->getAdapter()->changeColumn($this->getName(), $column);
     return $this;
 }