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


PHP Column::setPrimaryKey方法代码示例

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


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

示例1: addClosureColumn

 protected function addClosureColumn($name, Table $ct_table, Column $column)
 {
     $table = $this->getTable();
     $id_fieldname = $column->getName();
     $domain = $column->getDomain();
     if (!$ct_table->hasColumn($name)) {
         $column = new Column($name);
         $column->setDomain($domain);
         $column->setPrimaryKey(true);
         $ct_table->addColumn($column);
     } else {
         $column = $ct_table->getColumn($name);
     }
     $ct_tablename_normalized = str_replace('_', '', $ct_table->getName());
     $fk_name = $ct_tablename_normalized . '_' . $name . '_fk';
     if (!$ct_table->getColumnForeignKeys($name)) {
         $column_fk = new ForeignKey($fk_name);
         $column_fk->addReference($name, $table->getColumn($id_fieldname)->getName());
         $column_fk->setForeignTableCommonName($table->getName());
         $column_fk->setOnUpdate('cascade');
         $column_fk->setOnDelete('restrict');
         $ct_table->addForeignKey($column_fk);
     }
     $column_idx_name = $fk_name . '_idx';
     if (!$ct_table->hasIndex($column_idx_name)) {
         $column_idx = new Index($column_idx_name);
         $column_idx->addColumn(['name' => $column->getName()]);
         $ct_table->addIndex($column_idx);
     }
 }
开发者ID:scif,项目名称:propel-closuretable-behavior,代码行数:30,代码来源:ClosureTableBehavior.php

示例2: 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:disider,项目名称:Propel2,代码行数:12,代码来源:SqlitePlatformTest.php

示例3: addColumns

 /**
  * Adds Columns to the specified table.
  *
  * @param Table $table The Table model class to add columns to.
  */
 protected function addColumns(Table $table)
 {
     $stmt = $this->dbh->query("PRAGMA table_info('" . $table->getName() . "')");
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $name = $row['name'];
         $fulltype = $row['type'];
         $size = null;
         $precision = null;
         $scale = null;
         if (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
             $type = $matches[1];
             $precision = $matches[2];
             $scale = $matches[3];
             // aka precision
         } elseif (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
             $type = $matches[1];
             $size = $matches[2];
         } else {
             $type = $fulltype;
         }
         // If column is primary key and of type INTEGER, it is auto increment
         // See: http://sqlite.org/faq.html#q1
         $autoincrement = 1 == $row['pk'] && 'integer' === strtolower($type);
         $notNull = $row['notnull'];
         $default = $row['dflt_value'];
         $propelType = $this->getMappedPropelType(strtolower($type));
         if (!$propelType) {
             $propelType = Column::DEFAULT_TYPE;
             $this->warn('Column [' . $table->getName() . '.' . $name . '] has a column type (' . $type . ') that Propel does not support.');
         }
         $column = new Column($name);
         $column->setTable($table);
         $column->setDomainForType($propelType);
         // We may want to provide an option to include this:
         // $column->getDomain()->replaceSqlType($type);
         $column->getDomain()->replaceSize($size);
         $column->getDomain()->replaceScale($scale);
         if (null !== $default) {
             $column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, ColumnDefaultValue::TYPE_VALUE));
         }
         $column->setAutoIncrement($autoincrement);
         $column->setNotNull($notNull);
         if (1 == $row['pk'] || 'integer' === strtolower($type)) {
             $column->setPrimaryKey(true);
         }
         $table->addColumn($column);
     }
 }
开发者ID:robin850,项目名称:Propel2,代码行数:53,代码来源:SqliteSchemaParser.php

示例4: addColumns

 /**
  * Adds Columns to the specified table.
  *
  * @param Table $table The Table model class to add columns to.
  */
 protected function addColumns(Table $table)
 {
     $tableName = $table->getName();
     //        var_dump("PRAGMA table_info('$tableName') //");
     $stmt = $this->dbh->query("PRAGMA table_info('{$tableName}')");
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $name = $row['name'];
         $fulltype = $row['type'];
         $size = null;
         $scale = null;
         if (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
             $type = $matches[1];
             $size = $matches[2];
             $scale = $matches[3];
         } elseif (preg_match('/^([^\\(]+)\\(\\s*(\\d+)\\s*\\)$/', $fulltype, $matches)) {
             $type = $matches[1];
             $size = $matches[2];
         } else {
             $type = $fulltype;
         }
         $notNull = $row['notnull'];
         $default = $row['dflt_value'];
         $propelType = $this->getMappedPropelType(strtolower($type));
         if (!$propelType) {
             $propelType = Column::DEFAULT_TYPE;
             $this->warn('Column [' . $table->getName() . '.' . $name . '] has a column type (' . $type . ') that Propel does not support.');
         }
         $column = new Column($name);
         $column->setTable($table);
         $column->setDomainForType($propelType);
         // We may want to provide an option to include this:
         // $column->getDomain()->replaceSqlType($type);
         $column->getDomain()->replaceSize($size);
         $column->getDomain()->replaceScale($scale);
         if (null !== $default) {
             if ("'" !== substr($default, 0, 1) && strpos($default, '(')) {
                 $defaultType = ColumnDefaultValue::TYPE_EXPR;
                 if ('datetime(CURRENT_TIMESTAMP, \'localtime\')' === $default) {
                     $default = 'CURRENT_TIMESTAMP';
                 }
             } else {
                 $defaultType = ColumnDefaultValue::TYPE_VALUE;
                 $default = str_replace("'", '', $default);
             }
             $column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $defaultType));
         }
         $column->setNotNull($notNull);
         if (0 < $row['pk'] + 0) {
             $column->setPrimaryKey(true);
         }
         if ($column->isPrimaryKey()) {
             // check if autoIncrement
             $autoIncrementStmt = $this->dbh->prepare('
             SELECT tbl_name
             FROM sqlite_master
             WHERE
               tbl_name = ?
             AND
               sql LIKE "%AUTOINCREMENT%"
             ');
             $autoIncrementStmt->execute([$table->getName()]);
             $autoincrementRow = $autoIncrementStmt->fetch(\PDO::FETCH_ASSOC);
             if ($autoincrementRow && $autoincrementRow['tbl_name'] == $table->getName()) {
                 $column->setAutoIncrement(true);
             }
         }
         $table->addColumn($column);
     }
 }
开发者ID:KyleGoslan,项目名称:Huge-Propel,代码行数:74,代码来源:SqliteSchemaParser.php

示例5: Column

$column41 = new Column('id', 'integer', 7);
$column41->setAutoIncrement();
$column41->setNotNull();
$column41->setPrimaryKey();
$column42 = new Column('name', 'varchar', 40);
$column42->setNotNull();
$column51 = new Column('post_id', 'integer', 7);
$column51->setNotNull();
$column51->setPrimaryKey();
$column52 = new Column('tag_id', 'integer', 7);
$column52->setNotNull();
$column52->setPrimaryKey();
$column61 = new Column('id', 'integer', 5);
$column61->setNotNull();
$column61->setAutoIncrement();
$column61->setPrimaryKey();
$column62 = new Column('title', 'varchar', 150);
$column62->setNotNull();
$column63 = new Column('content', 'clob');
$column63->addVendorInfo(new VendorInfo('mysql', ['Charset' => 'latin1', 'Collate' => 'latin1_general_ci']));
$column64 = new Column('is_published', 'boolean');
$column64->setNotNull();
$column64->setDefaultValue('false');
/* Foreign Keys */
$fkAuthorPost = new ForeignKey('fk_post_has_author');
$fkAuthorPost->addReference('author_id', 'id');
$fkAuthorPost->setForeignTableCommonName('blog_author');
$fkAuthorPost->setRefPhpName('Posts');
$fkAuthorPost->setPhpName('Author');
$fkAuthorPost->setDefaultJoin('Criteria::LEFT_JOIN');
$fkAuthorPost->setOnDelete('CASCADE');
开发者ID:disider,项目名称:Propel2,代码行数:31,代码来源:blog-database.php

示例6: testReverseDiffHasRenamedPkColumn

 public function testReverseDiffHasRenamedPkColumn()
 {
     $fromColumn = new Column('post_id', 'integer');
     $fromColumn->setPrimaryKey();
     $toColumn = new Column('id', 'integer');
     $toColumn->setPrimaryKey();
     $diff = $this->createTableDiff();
     $diff->addRenamedPkColumn($fromColumn, $toColumn);
     $reverseDiff = $diff->getReverseDiff();
     $this->assertTrue($reverseDiff->hasRenamedPkColumns());
     $this->assertSame([[$toColumn, $fromColumn]], $reverseDiff->getRenamedPkColumns());
 }
开发者ID:disider,项目名称:Propel2,代码行数:12,代码来源:TableDiffTest.php

示例7: 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));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:9,代码来源:PlatformTestProvider.php

示例8: 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());
 }
开发者ID:disider,项目名称:Propel2,代码行数:45,代码来源:PropelTablePkColumnComparatorTest.php

示例9: testCompareSeveralPrimaryKeyDifferences

 public function testCompareSeveralPrimaryKeyDifferences()
 {
     $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);
     $c2->setPrimaryKey(true);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $c3->setPrimaryKey(true);
     $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);
     $c5->setPrimaryKey(true);
     $t2->addColumn($c5);
     $c6 = new Column('col4');
     $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR'));
     $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE));
     $c6->setPrimaryKey(true);
     $t2->addColumn($c6);
     // col2 was renamed, col3 was removed, col4 was added
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->comparePrimaryKeys();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(3, $nbDiffs);
     $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedPkColumns());
     $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedPkColumns());
     $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedPkColumns());
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:47,代码来源:PropelTablePkColumnComparatorTest.php

示例10: testValidateReturnsTrueWhenTwoTablesHaveSamePhpNameInDifferentNamespaces

 public function testValidateReturnsTrueWhenTwoTablesHaveSamePhpNameInDifferentNamespaces()
 {
     $column1 = new Column('id');
     $column1->setPrimaryKey(true);
     $table1 = new Table('foo');
     $table1->addColumn($column1);
     $table1->setNamespace('Foo');
     $column2 = new Column('id');
     $column2->setPrimaryKey(true);
     $table2 = new Table('bar');
     $table2->addColumn($column2);
     $table2->setPhpName('Foo');
     $table2->setNamespace('Bar');
     $database = new Database();
     $database->addTable($table1);
     $database->addTable($table2);
     $schema = new Schema();
     $schema->addDatabase($database);
     $validator = new SchemaValidator($schema);
     $this->assertTrue($validator->validate());
 }
开发者ID:robin850,项目名称:Propel2,代码行数:21,代码来源:SchemaValidatorTest.php


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