本文整理汇总了PHP中Propel\Generator\Model\Table::addColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::addColumn方法的具体用法?PHP Table::addColumn怎么用?PHP Table::addColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Table
的用法示例。
在下文中一共展示了Table::addColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _before
/**
* @return void
*/
protected function _before()
{
$config = new QuickGeneratorConfig();
$table = new Table('Foo');
$column = new Column('testColumn', PropelTypes::INTEGER);
$table->addColumn($column);
$table->setNamespace('Unit\\Spryker\\Zed\\Propel\\Business\\Builder\\QueryBuilder');
$table->setDatabase(new Database('TestDB', new DefaultPlatform()));
foreach ($this->getFilesToGenerate() as $fileName => $builderClass) {
$builder = new $builderClass($table);
$builder->setGeneratorConfig($config);
$this->writePropelFile($builder, $fileName);
}
}
示例2: testGetIndexDDLFulltext
public function testGetIndexDDLFulltext()
{
$table = new Table('foo');
$table->setIdentifierQuoting(true);
$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));
}
示例3: 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 = ColumnComparator::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));
}
示例4: testCompareSeveralTableDifferences
public function testCompareSeveralTableDifferences()
{
$d1 = new Database();
$t1 = new Table('Foo_Table');
$c1 = new Column('Foo');
$c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
$c1->getDomain()->replaceScale(2);
$c1->getDomain()->replaceSize(3);
$c1->setNotNull(true);
$c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
$t1->addColumn($c1);
$d1->addTable($t1);
$t2 = new Table('Bar');
$c2 = new Column('Bar_Column');
$c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
$t2->addColumn($c2);
$d1->addTable($t2);
$t11 = new Table('Baz');
$d1->addTable($t11);
$d2 = new Database();
$t3 = new Table('Foo_Table');
$c3 = new Column('Foo1');
$c3->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
$c3->getDomain()->replaceScale(2);
$c3->getDomain()->replaceSize(3);
$c3->setNotNull(true);
$c3->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
$t3->addColumn($c3);
$d2->addTable($t3);
$t4 = new Table('Bar2');
$c4 = new Column('Bar_Column');
$c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
$t4->addColumn($c4);
$d2->addTable($t4);
$t5 = new Table('Biz');
$c5 = new Column('Biz_Column');
$c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$t5->addColumn($c5);
$d2->addTable($t5);
// Foo_Table was modified, Bar was renamed, Baz was removed, Biz was added
$dc = new DatabaseComparator();
$dc->setFromDatabase($d1);
$dc->setToDatabase($d2);
$nbDiffs = $dc->compareTables();
$databaseDiff = $dc->getDatabaseDiff();
$this->assertEquals(4, $nbDiffs);
$this->assertEquals(array('Bar' => 'Bar2'), $databaseDiff->getRenamedTables());
$this->assertEquals(array('Biz' => $t5), $databaseDiff->getAddedTables());
$this->assertEquals(array('Baz' => $t11), $databaseDiff->getRemovedTables());
$tableDiff = TableComparator::computeDiff($t1, $t3);
$this->assertEquals(array('Foo_Table' => $tableDiff), $databaseDiff->getModifiedTables());
}
示例5: 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()));
}
示例6: testExcludedTablesWithRenaming
public function testExcludedTablesWithRenaming()
{
$dc = new DatabaseComparator();
$this->assertCount(0, $dc->getExcludedTables());
$dc->setExcludedTables(array('foo'));
$this->assertCount(1, $dc->getExcludedTables());
$d1 = new Database();
$d2 = new Database();
$t2 = new Table('Bar');
$d2->addTable($t2);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar'));
$this->assertFalse($diff);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Baz'));
$this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff);
$d1 = new Database();
$t1 = new Table('Foo');
$d1->addTable($t1);
$d2 = new Database();
$t2 = new Table('Bar');
$d2->addTable($t2);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar', 'Foo'));
$this->assertFalse($diff);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Foo'));
$this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar'));
$this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff);
$d1 = new Database();
$t1 = new Table('Foo');
$c1 = new Column('col1');
$t1->addColumn($c1);
$d1->addTable($t1);
$d2 = new Database();
$t2 = new Table('Foo');
$d2->addTable($t2);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar', 'Foo'));
$this->assertFalse($diff);
$diff = DatabaseComparator::computeDiff($d1, $d2, false, true, true, array('Bar'));
$this->assertInstanceOf('Propel\\Generator\\Model\\Diff\\DatabaseDiff', $diff);
}
示例7: 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));
}
示例8: 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());
}
示例9: providerForTestPrimaryKeyDDL
public function providerForTestPrimaryKeyDDL()
{
$table = new Table('foo');
$table->setIdentifierQuoting(true);
$column = new Column('bar');
$column->setPrimaryKey(true);
$table->addColumn($column);
return array(array($table));
}
示例10: providerForTestGetForeignKeysDDL
public function providerForTestGetForeignKeysDDL()
{
$table1 = new Table('foo');
$column1 = new Column('bar_id');
$column1->getDomain()->copy(new Domain('FOOTYPE'));
$table1->addColumn($column1);
$table2 = new Table('bar');
$column2 = new Column('id');
$column2->getDomain()->copy(new Domain('BARTYPE'));
$table2->addColumn($column2);
$fk = new ForeignKey('foo_bar_fk');
$fk->setForeignTableCommonName('bar');
$fk->addReference($column1, $column2);
$fk->setOnDelete('CASCADE');
$table1->addForeignKey($fk);
$column3 = new Column('baz_id');
$column3->getDomain()->copy(new Domain('BAZTYPE'));
$table1->addColumn($column3);
$table3 = new Table('baz');
$column4 = new Column('id');
$column4->getDomain()->copy(new Domain('BAZTYPE'));
$table3->addColumn($column4);
$fk = new ForeignKey('foo_baz_fk');
$fk->setForeignTableCommonName('baz');
$fk->addReference($column3, $column4);
$fk->setOnDelete('SETNULL');
$table1->addForeignKey($fk);
return array(array($table1));
}
示例11: addLogColumns
protected function addLogColumns(Table $table)
{
if ('true' === $this->getParameter('created_at') && !$table->hasColumn($this->getParameter('created_at_column'))) {
$table->addColumn(array('name' => $this->getParameter('created_at_column'), 'type' => 'TIMESTAMP'));
}
if ('true' === $this->getParameter('created_by') && !$table->hasColumn($this->getParameter('created_by_column'))) {
$table->addColumn(array('name' => $this->getParameter('created_by_column'), 'type' => 'VARCHAR', 'size' => 100));
}
if ('true' === $this->getParameter('comment') && !$table->hasColumn($this->getParameter('comment_column'))) {
$table->addColumn(array('name' => $this->getParameter('comment_column'), 'type' => 'VARCHAR', 'size' => 255));
}
}
示例12: startElement
public function startElement($parser, $name, $attributes)
{
$parentTag = $this->peekCurrentSchemaTag();
if (false === $parentTag) {
switch ($name) {
case 'database':
if ($this->isExternalSchema()) {
$this->currentPackage = isset($attributes['package']) ? $attributes['package'] : null;
if (null === $this->currentPackage) {
$this->currentPackage = $this->defaultPackage;
}
} else {
$this->currDB = $this->schema->addDatabase($attributes);
}
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
} elseif ('database' === $parentTag) {
switch ($name) {
case 'external-schema':
$xmlFile = isset($attributes['filename']) ? $attributes['filename'] : null;
// 'referenceOnly' attribute is valid in the main schema XML file only,
// and it's ignored in the nested external-schemas
if (!$this->isExternalSchema()) {
$isForRefOnly = isset($attributes['referenceOnly']) ? $attributes['referenceOnly'] : null;
$this->isForReferenceOnly = null !== $isForRefOnly ? 'true' === strtolower($isForRefOnly) : true;
// defaults to TRUE
}
if ('/' !== $xmlFile[0]) {
$xmlFile = realpath(dirname($this->currentXmlFile) . DIRECTORY_SEPARATOR . $xmlFile);
if (!file_exists($xmlFile)) {
throw new SchemaException(sprintf('Unknown include external "%s"', $xmlFile));
}
}
$this->parseFile($xmlFile);
break;
case 'domain':
$this->currDB->addDomain($attributes);
break;
case 'table':
if (!isset($attributes['schema']) && $this->currDB->getSchema() && $this->currDB->getPlatform()->supportsSchemas() && false === strpos($attributes['name'], $this->currDB->getPlatform()->getSchemaDelimiter())) {
$attributes['schema'] = $this->currDB->getSchema();
}
$this->currTable = $this->currDB->addTable($attributes);
if ($this->isExternalSchema()) {
$this->currTable->setForReferenceOnly($this->isForReferenceOnly);
$this->currTable->setPackage($this->currentPackage);
}
break;
case 'vendor':
$this->currVendorObject = $this->currDB->addVendorInfo($attributes);
break;
case 'behavior':
$this->currBehavior = $this->currDB->addBehavior($attributes);
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
} elseif ('table' === $parentTag) {
switch ($name) {
case 'column':
$this->currColumn = $this->currTable->addColumn($attributes);
break;
case 'foreign-key':
$this->currFK = $this->currTable->addForeignKey($attributes);
break;
case 'index':
$this->currIndex = new Index();
$this->currIndex->setTable($this->currTable);
$this->currIndex->loadMapping($attributes);
break;
case 'unique':
$this->currUnique = new Unique();
$this->currUnique->setTable($this->currTable);
$this->currUnique->loadMapping($attributes);
break;
case 'vendor':
$this->currVendorObject = $this->currTable->addVendorInfo($attributes);
break;
case 'id-method-parameter':
$this->currTable->addIdMethodParameter($attributes);
break;
case 'behavior':
$this->currBehavior = $this->currTable->addBehavior($attributes);
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
} elseif ('column' === $parentTag) {
switch ($name) {
case 'inheritance':
$this->currColumn->addInheritance($attributes);
break;
case 'vendor':
$this->currVendorObject = $this->currColumn->addVendorInfo($attributes);
break;
default:
$this->_throwInvalidTagException($parser, $name);
}
//.........这里部分代码省略.........
示例13: testCompareSeveralRenamedSamePrimaryKeys
public function testCompareSeveralRenamedSamePrimaryKeys()
{
$t1 = new Table();
$c1 = new Column('col1');
$c1->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c1->setNotNull(true);
$c1->setPrimaryKey(true);
$t1->addColumn($c1);
$c2 = new Column('col2');
$c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c2->setNotNull(true);
$c2->setPrimaryKey(true);
$t1->addColumn($c2);
$c3 = new Column('col3');
$c3->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c3->setNotNull(true);
$c3->setPrimaryKey(true);
$t1->addColumn($c3);
$t2 = new Table();
$c4 = new Column('col4');
$c4->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c4->setNotNull(true);
$c4->setPrimaryKey(true);
$t2->addColumn($c4);
$c5 = new Column('col5');
$c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c5->setNotNull(true);
$c5->setPrimaryKey(true);
$t2->addColumn($c5);
$c6 = new Column('col3');
$c6->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
$c6->setNotNull(true);
$c6->setPrimaryKey(true);
$t2->addColumn($c6);
// col1 and col2 were renamed
$tc = new TableComparator();
$tc->setFromTable($t1);
$tc->setToTable($t2);
$nbDiffs = $tc->comparePrimaryKeys();
$tableDiff = $tc->getTableDiff();
$this->assertEquals(2, $nbDiffs);
$this->assertEquals([[$c1, $c4], [$c2, $c5]], $tableDiff->getRenamedPkColumns());
$this->assertEquals([], $tableDiff->getAddedPkColumns());
$this->assertEquals([], $tableDiff->getRemovedPkColumns());
}
示例14: testHasPlatform
public function testHasPlatform()
{
$column = new Column();
$this->assertFalse($column->hasPlatform());
$table = new Table();
$table->addColumn($column);
$this->assertFalse($column->hasPlatform());
$database = new Database();
$database->addTable($table);
$this->assertFalse($column->hasPlatform());
$platform = new DefaultPlatform();
$database->setPlatform($platform);
$this->assertTrue($column->hasPlatform());
}
示例15: addColumn
protected function addColumn(Table $table, $name)
{
if (!$table->hasColumn($name)) {
$column = new Column($name);
// don't know how to define unsigned :(
$domain = new Domain('TINYINT', 'tinyint(3) unsigned');
$column->setDomain($domain);
$table->addColumn($column);
$column_idx_name = $name . '_idx';
if (!$table->hasIndex($column_idx_name)) {
$column_idx = new Index($column_idx_name);
$column_idx->addColumn(['name' => $column->getName()]);
$table->addIndex($column_idx);
}
}
}