本文整理汇总了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)));
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
示例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()));
}
示例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));
}
示例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));
}
示例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;
}
示例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());
}
示例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));
}
示例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());
}
示例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));
}
示例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));
}
}