コード例 #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();
 }
コード例 #2
0
 private function getCols(\blaze\ds\meta\ColumnMetaData $column)
 {
     $stmt = null;
     $rs = null;
     $constType = null;
     $constraint = null;
     try {
         $con = $column->getTable()->getSchema()->getDatabaseMetaData()->getConnection();
         $stmt = $con->prepareStatement('SELECT * FROM information_schema.TABLE_CONSTRAINTS JOIN information_schema.KEY_COLUMN_USAGE ON KEY_COLUMN_USAGE.TABLE_SCHEMA = TABLE_CONSTRAINTS.TABLE_SCHEMA AND KEY_COLUMN_USAGE.TABLE_NAME = TABLE_CONSTRAINTS.TABLE_NAME AND KEY_COLUMN_USAGE.CONSTRAINT_NAME = TABLE_CONSTRAINTS.CONSTRAINT_NAME WHERE KEY_COLUMN_USAGE.TABLE_SCHEMA = ? AND KEY_COLUMN_USAGE.TABLE_NAME = ? AND KEY_COLUMN_USAGE.CONSTRAINT_NAME = ?');
         $stmt->setString(0, $column->getTable()->getSchema()->getSchemaName());
         $stmt->setString(1, $column->getTable()->getTableName());
         $stmt->setString(2, $constraintName);
         $stmt->execute();
         //            $rs = $stmt->getResultSet();
         //            $rsmd = $stmt->getMetaData();
         //
         //            while($rs->next())
         //                    $tblConst[$rs->getString('CONSTRAINT_NAME')->toString()] = $rs->getString('CONSTRAINT_TYPE');
         //
         //            if($stmt != null)
         //                $stmt->close();
         //            if($rs != null)
         //                $rs->close();
         //
         //            $stmt = $this->table->getSchema()->getDatabaseMetaData()->getConnection()->prepareStatement('SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?');
         //            $stmt->setString(0, $this->table->getSchema()->getSchemaName());
         //            $stmt->setString(1, $this->table->getTableName());
         //            $stmt->setString(2, $this->columnName);
         //            $stmt->execute();
         //            $rs = $stmt->getResultSet();
         //
         //            while($rs->next()){
         //                switch($tblConst[$rs->getString('CONSTRAINT_NAME')->toString()]){
         //                    case 'PRIMARY KEY':
         //                        $constraint = new ConstraintMetaDataImpl($this, $rs->getString('CONSTRAINT_NAME'), 'PRIMARY KEY');
         //                        break;
         //                    case 'FOREIGN KEY':
         //                        $refSch = $this->table
         //                                       ->getSchema()
         //                                       ->getDatabaseMetaData()
         //                                       ->getSchema($rs->getString('REFERENCED_TABLE_SCHEMA'));
         //
         //                        if($refSch == null)
         //                            break;
         //
         //                        $refCol = $refSch->getTable($rs->getString('REFERENCED_TABLE_NAME'))
         //                                       ->getColumn($rs->getString('REFERENCED_COLUMN_NAME'));
         //                        $constraint = new ForeignKeyMetaDataImpl($this, $refCol, $rs->getString('CONSTRAINT_NAME'));
         //                        break;
         //                    case 'UNIQUE':
         //                        $constraint = new ConstraintMetaDataImpl($this, $rs->getString('CONSTRAINT_NAME'), 'UNIQUE KEY');
         //                        break;
         //                    default:
         //                        $constraint = new ConstraintMetaDataImpl($this, $rs->getString('CONSTRAINT_NAME'), 'UNKNOWN');
         //                        break;
         //                }
         //            }
     } catch (\blaze\ds\DataSourceException $e) {
         throw $e;
     }
     if ($stmt != null) {
         $stmt->close();
     }
     if ($rs != null) {
         $rs->close();
     }
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 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));
     }
 }