当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::addColumn方法代码示例

本文整理汇总了PHP中Table::addColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addColumn方法的具体用法?PHP Table::addColumn怎么用?PHP Table::addColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Table的用法示例。


在下文中一共展示了Table::addColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     $this->target = new Table('tableName');
     $this->target->addColumn(new Column(array('name' => 'id', 'dataType' => 'bigint(100)', 'primary' => true, 'autoIncrement' => true, 'notNull' => true, 'default' => null)));
     $this->target->addColumn(new Column(array('name' => 'col1', 'dataType' => 'VARCHAR(255)', 'primary' => false, 'autoIncrement' => false, 'notNull' => true, 'default' => null)));
     $this->target->addColumn(new Column(array('name' => 'col2', 'dataType' => 'double', 'primary' => false, 'autoIncrement' => false, 'notNull' => false, 'default' => null)));
 }
开发者ID:aainc,项目名称:Scruit,代码行数:7,代码来源:TableTest.php

示例2: addColumn

 /**
  * @param string $columnName
  * @param string $typeName
  * @param array $options
  *
  * @return Column
  */
 public function addColumn($columnName, $typeName, array $options = array())
 {
     if ($this->connection->getDatabasePlatform()->getName() === 'sqlite' && in_array($typeName, ['string', 'text'])) {
         $options['customSchemaOptions']['collation'] = 'NOCASE';
     }
     return $this->table->addColumn($columnName, $typeName, $options);
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:14,代码来源:Table.php

示例3: createTaggingTable

 protected function createTaggingTable()
 {
     $table = $this->getTable();
     $database = $table->getDatabase();
     $pks = $this->getTable()->getPrimaryKey();
     if (count($pks) > 1) {
         throw new EngineException('The Taggable behavior does not support tables with composite primary keys');
     }
     $taggingTableName = $this->getTaggingTableName();
     if ($database->hasTable($taggingTableName)) {
         $this->taggingTable = $database->getTable($taggingTableName);
     } else {
         $this->taggingTable = $database->addTable(array('name' => $taggingTableName, 'phpName' => $this->replaceTokens($this->getParameter('tagging_table_phpname')), 'package' => $table->getPackage(), 'schema' => $table->getSchema(), 'namespace' => '\\' . $table->getNamespace()));
         // every behavior adding a table should re-execute database behaviors
         // see bug 2188 http://www.propelorm.org/changeset/2188
         foreach ($database->getBehaviors() as $behavior) {
             $behavior->modifyDatabase();
         }
     }
     if ($this->taggingTable->hasColumn('tag_id')) {
         $tagFkColumn = $this->taggingTable->getColumn('tag_id');
     } else {
         $tagFkColumn = $this->taggingTable->addColumn(array('name' => 'tag_id', 'type' => PropelTypes::INTEGER, 'primaryKey' => 'true'));
     }
     if ($this->taggingTable->hasColumn($table->getName() . '_id')) {
         $objFkColumn = $this->taggingTable->getColumn($table->getName() . '_id');
     } else {
         $objFkColumn = $this->taggingTable->addColumn(array('name' => $table->getName() . '_id', 'type' => PropelTypes::INTEGER, 'primaryKey' => 'true'));
     }
     $this->taggingTable->setIsCrossRef(true);
     $fkTag = new ForeignKey();
     $fkTag->setForeignTableCommonName($this->tagTable->getCommonName());
     $fkTag->setForeignSchemaName($this->tagTable->getSchema());
     $fkTag->setOnDelete(ForeignKey::CASCADE);
     $fkTag->setOnUpdate(ForeignKey::CASCADE);
     $tagColumn = $this->tagTable->getColumn('id');
     $fkTag->addReference($tagFkColumn->getName(), $tagColumn->getName());
     $this->taggingTable->addForeignKey($fkTag);
     $fkObj = new ForeignKey();
     $fkObj->setForeignTableCommonName($this->getTable()->getCommonName());
     $fkObj->setForeignSchemaName($this->getTable()->getSchema());
     $fkObj->setOnDelete(ForeignKey::CASCADE);
     $fkObj->setOnUpdate(ForeignKey::CASCADE);
     foreach ($pks as $column) {
         $fkObj->addReference($objFkColumn->getName(), $column->getName());
     }
     $this->taggingTable->addForeignKey($fkObj);
 }
开发者ID:k3dbe,项目名称:propel-taggable-behavior,代码行数:48,代码来源:TaggableBehavior.php

示例4: addToTable

 private function addToTable($tableName, Column $column)
 {
     foreach ($this->tables as $table) {
         if ($table->name == $tableName) {
             $table->addColumn($column);
             return;
         }
     }
     $table = new Table($tableName);
     $table->addColumn($column);
     $this->tables[] = $table;
 }
开发者ID:votemike,项目名称:dbhelper,代码行数:12,代码来源:TableCollection.php

示例5: testCompareSeveralRenamedSameColumns

 public function testCompareSeveralRenamedSameColumns()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c2->getDomain()->replaceSize(255);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col4');
     $c4->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c4->getDomain()->replaceSize(255);
     $t2->addColumn($c4);
     $c5 = new Column('col5');
     $c5->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c5->getDomain()->replaceSize(255);
     $t2->addColumn($c5);
     $c6 = new Column('col3');
     $c6->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c6->getDomain()->replaceSize(255);
     $t2->addColumn($c6);
     // col1 and col2 were renamed
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(2, $nbDiffs);
     $this->assertEquals(array(array($c1, $c4), array($c2, $c5)), $tableDiff->getRenamedColumns());
     $this->assertEquals(array(), $tableDiff->getAddedColumns());
     $this->assertEquals(array(), $tableDiff->getRemovedColumns());
     $this->assertEquals(array(), $tableDiff->getModifiedColumns());
 }
开发者ID:thehereward,项目名称:Propel,代码行数:40,代码来源:PropelTableColumnComparatorTest.php

示例6: convertColumnDescription

 /**
  * {@inheritDoc}
  */
 public function convertColumnDescription(Table $table, $row)
 {
     $field = $this->_convertColumn($row['type'], $row['char_length'], $row['precision'], $row['scale']);
     if (!empty($row['default'])) {
         $row['default'] = trim($row['default'], '()');
     }
     if (!empty($row['autoincrement'])) {
         $field['autoIncrement'] = true;
     }
     if ($field['type'] === 'boolean') {
         $row['default'] = (int) $row['default'];
     }
     $field += ['null' => $row['null'] === '1' ? true : false, 'default' => $row['default']];
     $table->addColumn($row['name'], $field);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:18,代码来源:SqlserverSchema.php

示例7: testRemoveColumnFixesPositions

 public function testRemoveColumnFixesPositions()
 {
     $table = new Table();
     $col1 = new Column('Foo1');
     $table->addColumn($col1);
     $col2 = new Column('Foo2');
     $table->addColumn($col2);
     $col3 = new Column('Foo3');
     $table->addColumn($col3);
     $this->assertEquals(1, $col1->getPosition());
     $this->assertEquals(2, $col2->getPosition());
     $this->assertEquals(3, $col3->getPosition());
     $this->assertEquals(array(0, 1, 2), array_keys($table->getColumns()));
     $table->removeColumn($col2);
     $this->assertEquals(1, $col1->getPosition());
     $this->assertEquals(2, $col3->getPosition());
     $this->assertEquals(array(0, 1), array_keys($table->getColumns()));
 }
开发者ID:keneanung,项目名称:gw2spidy,代码行数:18,代码来源:TableTest.php

示例8: testGetPrimaryKeyDDLCompositeKey

 public function testGetPrimaryKeyDDLCompositeKey()
 {
     $table = new Table('foo');
     $column1 = new Column('bar1');
     $column1->setPrimaryKey(true);
     $table->addColumn($column1);
     $column2 = new Column('bar2');
     $column2->setPrimaryKey(true);
     $table->addColumn($column2);
     $expected = 'PRIMARY KEY ([bar1],[bar2])';
     $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:12,代码来源:SqlitePlatformTest.php

示例9: testGetModifyColumnDDLWithChangedTypeAndDefault

    public function testGetModifyColumnDDLWithChangedTypeAndDefault()
    {
        $t1 = new Table('foo');
        $c1 = new Column('bar');
        $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
        $c1->getDomain()->replaceSize(2);
        $t1->addColumn($c1);
        $t2 = new Table('foo');
        $c2 = new Column('bar');
        $c2->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
        $c2->getDomain()->replaceSize(3);
        $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(-100, ColumnDefaultValue::TYPE_VALUE));
        $t2->addColumn($c2);
        $columnDiff = PropelColumnComparator::computeDiff($c1, $c2);
        $expected = <<<END

ALTER TABLE foo ALTER COLUMN bar TYPE DOUBLE PRECISION;

ALTER TABLE foo ALTER COLUMN bar SET DEFAULT -100;

END;
        $this->assertEquals($expected, $this->getPlatform()->getModifyColumnDDL($columnDiff));
    }
开发者ID:keneanung,项目名称:gw2spidy,代码行数:23,代码来源:PgsqlPlatformMigrationTest.php

示例10: getScheme

 public function getScheme()
 {
     $this->open();
     $rs = $this->connection->query('SHOW TABLES');
     $tables = array();
     while ($table = $rs->fetch_array()) {
         $rs2 = $this->connection->query("SHOW COLUMNS FROM {$table['0']}");
         $scheme = new Table($table[0]);
         while ($column = $rs2->fetch_object()) {
             $scheme->addColumn(new Column(array('name' => $column->Field, 'dataType' => $column->Type, 'primary' => $column->Key === "PRI", 'autoIncrement' => $column->Extra === "auto_increment", 'notNull' => $column->Null === 'NO', 'default' => $column->Default)));
         }
         $tables[] = $scheme;
     }
     return $tables;
 }
开发者ID:aainc,项目名称:Scruit,代码行数:15,代码来源:Session.php

示例11: testCompareSeveralColumnDifferences

 public function testCompareSeveralColumnDifferences()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c2->setNotNull(true);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col1');
     $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c4->getDomain()->replaceScale(2);
     $c4->getDomain()->replaceSize(3);
     $c4->setNotNull(true);
     $c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c4);
     $c5 = new Column('col22');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c5->setNotNull(true);
     $t2->addColumn($c5);
     $c6 = new Column('col4');
     $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR'));
     $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c6);
     // col1 was modified, col2 was renamed, col3 was removed, col4 was added
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns());
     $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns());
     $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns());
     $columnDiff = PropelColumnComparator::computeDiff($c1, $c4);
     $this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns());
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:45,代码来源:PropelTableColumnComparatorTest.php

示例12: testColumnIsFKAndPK

 public function testColumnIsFKAndPK()
 {
     $column = new Column();
     $column->setName('id');
     $column->setPrimaryKey(true);
     $column->setAutoIncrement(true);
     $column->setType('integer');
     $table = new Table();
     $table->setCommonName('table_one');
     $table->addColumn($column);
     $db = new Database();
     $db->setName('MultipleTables');
     $db->addTable($table);
     $column = new Column();
     $column->setName('id');
     $column->setPrimaryKey(true);
     $column->setAutoIncrement(true);
     $column->setType('integer');
     $c2 = new Column();
     $c2->setPrimaryKey(true);
     $c2->setName('foreign_id');
     $c2->setType('integer');
     $table = new Table();
     $table->setCommonName('table_two');
     $table->addColumn($column);
     $table->addColumn($c2);
     $fk = new ForeignKey();
     $fk->setName('FK_1');
     $fk->addReference('foreign_id', 'id');
     $fk->setForeignTableCommonName('table_one');
     $table->addForeignKey($fk);
     $db->addTable($table);
     $expected = implode("\n", array('digraph G {', 'nodetable_one [label="{<table>table_one|<cols>id (integer) [PK]\\l}", shape=record];', 'nodetable_two [label="{<table>table_two|<cols>id (integer) [PK]\\lforeign_id (integer) [FK] [PK]\\l}", shape=record];', 'nodetable_two:cols -> nodetable_one:table [label="foreign_id=id"];', '}', ''));
     $this->assertEquals($expected, PropelDotGenerator::create($db));
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:35,代码来源:PropelDotGeneratorTest.php

示例13: testCompareModifiedIndices

 public function testCompareModifiedIndices()
 {
     $t1 = new Table();
     $c1 = new Column('Foo');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $i1 = new Index('Foo_Index');
     $i1->addColumn($c1);
     $t1->addIndex($i1);
     $t2 = new Table();
     $c2 = new Column('Foo');
     $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c2->getDomain()->replaceScale(2);
     $c2->getDomain()->replaceSize(3);
     $c2->setNotNull(true);
     $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c2);
     $i2 = new Unique('Foo_Index');
     $i2->addColumn($c2);
     $t2->addIndex($i2);
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareIndices();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedIndices()));
     $this->assertEquals(array('Foo_Index' => array($i1, $i2)), $tableDiff->getModifiedIndices());
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:31,代码来源:PropelTableIndexComparatorTest.php

示例14: testGetIndexDDLFulltext

 public function testGetIndexDDLFulltext()
 {
     $table = new Table('foo');
     $column1 = new Column('bar1');
     $column1->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
     $table->addColumn($column1);
     $index = new Index('bar_index');
     $index->addColumn($column1);
     $vendor = new VendorInfo('mysql');
     $vendor->setParameter('Index_type', 'FULLTEXT');
     $index->addVendorInfo($vendor);
     $table->addIndex($index);
     $expected = 'FULLTEXT INDEX `bar_index` (`bar1`)';
     $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index));
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:15,代码来源:MysqlPlatformTest.php

示例15: _gatherColumn

 /**
  * Creates a column definition as required by the DBAL from an ORM field mapping definition.
  *
  * @param ClassMetadata $class The class that owns the field mapping.
  * @param array $mapping The field mapping.
  * @param Table $table
  * @return array The portable column definition as required by the DBAL.
  */
 private function _gatherColumn($class, array $mapping, $table)
 {
     $columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform);
     $columnType = $mapping['type'];
     $options = array();
     $options['length'] = isset($mapping['length']) ? $mapping['length'] : null;
     $options['notnull'] = isset($mapping['nullable']) ? !$mapping['nullable'] : true;
     $options['platformOptions'] = array();
     $options['platformOptions']['version'] = $class->isVersioned && $class->versionField == $mapping['fieldName'] ? true : false;
     if (strtolower($columnType) == 'string' && $options['length'] === null) {
         $options['length'] = 255;
     }
     if (isset($mapping['precision'])) {
         $options['precision'] = $mapping['precision'];
     }
     if (isset($mapping['scale'])) {
         $options['scale'] = $mapping['scale'];
     }
     if (isset($mapping['default'])) {
         $options['default'] = $mapping['default'];
     }
     if (isset($mapping['columnDefinition'])) {
         $options['columnDefinition'] = $mapping['columnDefinition'];
     }
     if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) {
         $options['autoincrement'] = true;
     }
     if ($table->hasColumn($columnName)) {
         // required in some inheritance scenarios
         $table->changeColumn($columnName, $options);
     } else {
         $table->addColumn($columnName, $columnType, $options);
     }
     $isUnique = isset($mapping['unique']) ? $mapping['unique'] : false;
     if ($isUnique) {
         $table->addUniqueIndex(array($columnName));
     }
 }
开发者ID:prolic,项目名称:doctrine2,代码行数:46,代码来源:SchemaTool.php


注:本文中的Table::addColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。