コード例 #1
0
 /**
  * Convert a MySQL column type into an abstract type.
  *
  * The returned type will be a type that Cake\Database\Type can handle.
  *
  * @param string $column The column type + length
  * @return array Array of column information.
  * @throws \Cake\Database\Exception When column type cannot be parsed.
  */
 protected function _convertColumn($column)
 {
     preg_match('/([a-z]+)(?:\\(([0-9,]+)\\))?\\s*([a-z]+)?/i', $column, $matches);
     if (empty($matches)) {
         throw new Exception(sprintf('Unable to parse column type from "%s"', $column));
     }
     $col = strtolower($matches[1]);
     $length = $precision = null;
     if (isset($matches[2])) {
         $length = $matches[2];
         if (strpos($matches[2], ',') !== false) {
             list($length, $precision) = explode(',', $length);
         }
         $length = (int) $length;
         $precision = (int) $precision;
     }
     if ($col === 'binary' && $length === 36) {
         return ['type' => 'uuid', 'length' => null];
     }
     return parent::_convertColumn($column);
 }
コード例 #2
0
ファイル: MysqlSchemaTest.php プロジェクト: rashmi/newrepo
 /**
  * Test generating a column that is a primary key.
  *
  * @return void
  */
 public function testColumnSqlPrimaryKey()
 {
     $driver = $this->_getMockedDriver();
     $schema = new MysqlSchema($driver);
     $table = new Table('articles');
     $table->addColumn('id', ['type' => 'integer', 'null' => false])->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
     $result = $schema->columnSql($table, 'id');
     $this->assertEquals($result, '`id` INTEGER NOT NULL AUTO_INCREMENT');
     $table = new Table('articles');
     $table->addColumn('id', ['type' => 'biginteger', 'null' => false])->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
     $result = $schema->columnSql($table, 'id');
     $this->assertEquals($result, '`id` BIGINT NOT NULL AUTO_INCREMENT');
 }