コード例 #1
0
ファイル: MySqlMapper.php プロジェクト: core-framework/core
 /**
  * Returns the SQL string containing all column specifications
  *
  * @param Column $column
  * @return string
  */
 protected function getColumnDefinition(Column $column)
 {
     $sql = "";
     $size = $column->getSize();
     $realDataType = $this->getRealDataType($column->getDataType(), $size);
     $sql .= strtoupper($realDataType['dataType']);
     $precision = $column->getPrecision();
     $scale = $column->getScale();
     if ($scale && $precision) {
         $sql .= "({$precision}, {$scale})";
     } elseif (isset($realDataType['size']) && is_array($realDataType['size'])) {
         $sql .= "({$realDataType['size']['precision']}, {$realDataType['size']['scale']})";
     } elseif (isset($realDataType['size'])) {
         $sql .= "({$realDataType['size']})";
     }
     if ($column->isSigned() && $this->signedDataTypes[$realDataType['dataType']]) {
         $sql .= " SIGNED";
     } elseif (isset($this->signedDataTypes[$realDataType['dataType']])) {
         $sql .= " UNSIGNED";
     }
     $sql .= $column->isNull() === true ? " NULL" : " NOT NULL";
     $sql .= $column->isAutoIncrement() === true ? " AUTO_INCREMENT" : '';
     $defaultVal = $column->getDefault();
     if (isset($defaultVal)) {
         $sql .= $this->getDefaultSqlStr($column);
     }
     $sql .= $column->getUpdate() ? " ON UPDATE {$column->getUpdate()}" : "";
     return $sql;
 }