Esempio n. 1
0
 public function apply(\blaze\ds\meta\ColumnMetaData $meta)
 {
     $this->name = $meta->getName();
     $this->className = $meta->getClassType();
     $this->comment = $meta->getComment();
     $this->default = $meta->getDefault();
     $this->length = $meta->getLength();
     $this->precision = $meta->getPrecision();
     $this->foreignKey = $meta->isForeignKey();
     $this->primaryKey = $meta->isPrimaryKey();
     $this->uniqueKey = $meta->isUniqueKey();
     $this->nullable = $meta->isNullable();
     $this->signed = $meta->isSigned();
 }
 public static function getColumnDefinition(\blaze\ds\meta\ColumnMetaData $column, $newName = null, $nullable = true, $default = true, $sequence = true, $primary = true, $unique = true, $comment = true)
 {
     if ($newName === null) {
         $query = $column->getName() . ' ' . $column->getComposedNativeType();
     } else {
         $query = $newName . ' ' . $column->getComposedNativeType();
     }
     if ($nullable && !$column->isNullable()) {
         $query .= ' NOT NULL';
     }
     if ($default && $column->getDefault() !== null) {
         $query .= ' DEFAULT ' . $column->getDefault();
     }
     if ($sequence && $column->getSequence() !== null) {
         $query .= ' AUTO_INCREMENT';
     }
     if ($primary && $column->isPrimaryKey()) {
         $query .= ' PRIMARY KEY';
     } else {
         if ($unique && $column->isUniqueKey()) {
             $query .= ' UNIQUE KEY';
         }
     }
     if ($comment && $column->getComment() !== null) {
         $query .= ' COMMENT \'' . $column->getComment() . '\'';
     }
     return $query;
 }
 public function addColumn(\blaze\ds\meta\ColumnMetaData $column, $newName = null)
 {
     if (!$this->initialized) {
         if ($newName === null) {
             $this->notInitializedColumns[\blaze\lang\String::asNative($column->getName())] = $column;
         } else {
             $this->notInitializedColumns[\blaze\lang\String::asNative($newName)] = $column;
         }
     } else {
         $this->checkClosed();
         $stmt = $this->schema->getDatabaseMetaData()->getConnection()->createStatement();
         $stmt->executeQuery('ALTER TABLE ' . $this->tableName . ' ADD COLUMN ' . ColumnMetaDataImpl::getColumnDefinition($column, $newName));
     }
 }