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


PHP Table::setPrimaryKey方法代码示例

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


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

示例1: doExecute

 protected function doExecute()
 {
     $this->step('Creating schema');
     $configuration = new \Firenote\Configuration\Yaml($this->rootPath . 'config');
     $app = new \Firenote\Application($configuration);
     $this->createDatabase($configuration);
     $schema = $app['db']->getSchemaManager();
     if (!$schema instanceof \Doctrine\DBAL\Schema\AbstractSchemaManager) {
         throw new \Exception();
     }
     if (!$schema->tablesExist('users')) {
         $this->writeln('<info>Creating table users ...</info>');
         $users = new Table('users');
         $users->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
         $users->setPrimaryKey(array('id'));
         $users->addColumn('username', 'string', array('length' => 32));
         $users->addUniqueIndex(array('username'));
         $users->addColumn('password', 'string', array('length' => 255));
         $users->addColumn('roles', 'string', array('length' => 255));
         $users->addColumn('avatar', 'string', array('length' => 512));
         $schema->createTable($users);
         $this->writeln('<info>Adding admin user (admin/foo) ...</info>');
         $this->writeln('<comment>Please change this dummy password !</comment>');
         $app['db']->insert('users', array('username' => 'admin', 'password' => '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==', 'roles' => 'ROLE_ADMIN', 'avatar' => '/assets/firenote/avatars/avatar2.png'));
     } else {
         $this->writeln('Nothing to do !');
     }
 }
开发者ID:niktux,项目名称:firenote,代码行数:28,代码来源:DatabaseCreate.php

示例2: createTable

 private function createTable($name)
 {
     $table = new Schema\Table($this->tableName($name));
     $table->addColumn('id', Type::INTEGER, ['autoincrement' => true, 'unsigned' => true]);
     $table->setPrimaryKey(['id']);
     return $table;
 }
开发者ID:alanedwardes,项目名称:carbo,代码行数:7,代码来源:SchemaCurator.php

示例3: rebuildSchema

 /**
  * Drops the tables and rebuilds them
  */
 public function rebuildSchema()
 {
     $schemaManager = $this->conn->getSchemaManager();
     $productTable = new Table('product');
     $productTable->addColumn("id", "integer", array("unsigned" => true));
     $productTable->addColumn("name", "string", array("length" => 255));
     $productTable->addColumn('author_id', 'integer', array('notNull' => false));
     $productTable->addColumn("description", "text", array('notNull' => false));
     $productTable->addColumn("price", "decimal", array('scale' => 2, 'notNull' => false));
     $productTable->addColumn("is_published", "boolean");
     $productTable->addColumn('created_at', 'datetime');
     $productTable->setPrimaryKey(array("id"));
     $schemaManager->dropAndCreateTable($productTable);
     $userTable = new Table('user');
     $userTable->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
     $userTable->setPrimaryKey(array('id'));
     $userTable->addColumn('username', 'string', array('length' => 32));
     $userTable->addUniqueIndex(array('username'));
     $userTable->addColumn('password', 'string', array('length' => 255));
     $userTable->addColumn('roles', 'string', array('length' => 255));
     $userTable->addColumn('created_at', 'datetime');
     // add an author_id to product
     $productTable->addForeignKeyConstraint($userTable, array('author_id'), array('id'));
     $schemaManager->dropAndCreateTable($userTable);
 }
开发者ID:vinodpanicker,项目名称:behat,代码行数:28,代码来源:SchemaManager.php

示例4: testCreateTemporaryTableNotAutoCommitTransaction

 /**
  * @group DDC-1337
  * @return void
  */
 public function testCreateTemporaryTableNotAutoCommitTransaction()
 {
     if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || $this->_conn->getDatabasePlatform()->getName() == 'oracle') {
         $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere.");
     }
     $platform = $this->_conn->getDatabasePlatform();
     $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
     $tempTable = $platform->getTemporaryTableName("my_temporary");
     $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
     $table = new Table("nontemporary");
     $table->addColumn("id", "integer");
     $table->setPrimaryKey(array('id'));
     foreach ($platform->getCreateTableSQL($table) as $sql) {
         $this->_conn->executeQuery($sql);
     }
     $this->_conn->beginTransaction();
     $this->_conn->insert("nontemporary", array("id" => 1));
     $this->_conn->exec($createTempTableSQL);
     $this->_conn->insert("nontemporary", array("id" => 2));
     $this->_conn->rollback();
     try {
         $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
     } catch (\Exception $e) {
     }
     $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
     $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
 }
开发者ID:selimcr,项目名称:servigases,代码行数:31,代码来源:TemporaryTableTest.php

示例5: exportCreateTable

 /**
  * Exports create table SQL.
  *
  * @return string
  */
 protected function exportCreateTable()
 {
     $table = new Table(self::TABLE_NAME, array(), array(), array(), false, array());
     $table->addColumn('id', 'string', array('length' => 2, 'notnull' => true));
     $table->setPrimaryKey(array('id'));
     $table->addColumn('value', 'string', array('length' => 64));
     return array_pop($this->getConnection()->getDatabasePlatform()->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES)) . ';' . PHP_EOL;
 }
开发者ID:umpirsky,项目名称:list-generator,代码行数:13,代码来源:SqlExporter.php

示例6: testSearchPathSchemaChanges

 public function testSearchPathSchemaChanges()
 {
     $table = new Table("dbal510tbl");
     $table->addColumn('id', 'integer');
     $table->setPrimaryKey(array('id'));
     $this->_conn->getSchemaManager()->createTable($table);
     $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl');
     $comparator = new Comparator();
     $diff = $comparator->diffTable($onlineTable, $table);
     $this->assertFalse($diff);
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:11,代码来源:DBAL510Test.php

示例7: testListTableColumnsWithFixedStringTypeColumn

 public function testListTableColumnsWithFixedStringTypeColumn()
 {
     $table = new Table('list_table_columns_char');
     $table->addColumn('id', 'integer', array('notnull' => true));
     $table->addColumn('test', 'string', array('fixed' => true));
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $columns = $this->_sm->listTableColumns('list_table_columns_char');
     $this->assertArrayHasKey('test', $columns);
     $this->assertTrue($columns['test']->getFixed());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:11,代码来源:SQLAnywhereSchemaManagerTest.php

示例8: buildTable

 /**
  * Builds table structure.
  *
  * @param Table $table
  */
 protected function buildTable(Table $table)
 {
     $table->addColumn('id', 'bigint')->setUnsigned(true)->setAutoincrement(true);
     $table->addColumn('type', 'string')->setLength(1)->setComment('C-CREATE(INSERT),U-UPDATE,D-DELETE');
     $table->addColumn('document_type', 'string')->setLength(32);
     $table->addColumn('document_id', 'string')->setLength(32);
     $table->addColumn('timestamp', 'datetime');
     $table->addColumn('status', 'boolean', ['default' => self::STATUS_NEW])->setComment('0-new,1-inProgress,2-error');
     $table->setPrimaryKey(['id']);
     $table->addUniqueIndex(['type', 'document_type', 'document_id', 'status']);
 }
开发者ID:asev,项目名称:ConnectionsBundle,代码行数:16,代码来源:MysqlStorageManager.php

示例9: createTable

 public function createTable()
 {
     if ($this->isExistTable()) {
         return;
     }
     $table = new Table(self::TABLE_NAME);
     $table->addColumn('version', Type::STRING, array('length' => 255, 'notnull' => true, 'default' => ''));
     $table->addColumn('apply_at', Type::DATETIME, array('notnull' => false, 'default' => null));
     $table->setPrimaryKey(array('version'));
     $this->doctrine->getSchemaManager()->createTable($table);
 }
开发者ID:sickhye,项目名称:php-db-migrate,代码行数:11,代码来源:DbTable.php

示例10: testSwitchPrimaryKeyOrder

 public function testSwitchPrimaryKeyOrder()
 {
     $tableOld = new Table("test");
     $tableOld->addColumn('foo_id', 'integer');
     $tableOld->addColumn('bar_id', 'integer');
     $tableNew = clone $tableOld;
     $tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
     $tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
     $diff = $this->comparator->diffTable($tableOld, $tableNew);
     $sql = $this->platform->getAlterTableSQL($diff);
     $this->assertEquals(array('ALTER TABLE test DROP PRIMARY KEY', 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'), $sql);
 }
开发者ID:selimcr,项目名称:servigases,代码行数:12,代码来源:MySQLSchemaTest.php

示例11: testIsAutoincrementFor

 /**
  * @group DDC-1657
  */
 public function testIsAutoincrementFor()
 {
     $table = new Table("foo");
     $table->addColumn("id", "integer", array("autoincrement" => true));
     $table->setPrimaryKey(array("id"));
     $sequence = new Sequence("foo_id_seq");
     $sequence2 = new Sequence("bar_id_seq");
     $sequence3 = new Sequence("other.foo_id_seq");
     $this->assertTrue($sequence->isAutoIncrementsFor($table));
     $this->assertFalse($sequence2->isAutoIncrementsFor($table));
     $this->assertFalse($sequence3->isAutoIncrementsFor($table));
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:15,代码来源:SequenceTest.php

示例12: testListTableWithBinary

 public function testListTableWithBinary()
 {
     $tableName = 'test_binary_table';
     $table = new Table($tableName);
     $table->addColumn('id', 'integer');
     $table->addColumn('column_varbinary', 'binary', array());
     $table->addColumn('column_binary', 'binary', array('fixed' => true));
     $table->setPrimaryKey(array('id'));
     $this->_sm->createTable($table);
     $table = $this->_sm->listTableDetails($tableName);
     $this->assertInstanceOf('Doctrine\\DBAL\\Types\\BinaryType', $table->getColumn('column_varbinary')->getType());
     $this->assertFalse($table->getColumn('column_varbinary')->getFixed());
     $this->assertInstanceOf('Doctrine\\DBAL\\Types\\BinaryType', $table->getColumn('column_binary')->getType());
     $this->assertFalse($table->getColumn('column_binary')->getFixed());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:15,代码来源:DrizzleSchemaManagerTest.php

示例13: testUniquePrimaryKey

 public function testUniquePrimaryKey()
 {
     $keyTable = new Table("foo");
     $keyTable->addColumn("bar", "integer");
     $keyTable->addColumn("baz", "string");
     $keyTable->setPrimaryKey(array("bar"));
     $keyTable->addUniqueIndex(array("baz"));
     $oldTable = new Table("foo");
     $oldTable->addColumn("bar", "integer");
     $oldTable->addColumn("baz", "string");
     $c = new \Doctrine\DBAL\Schema\Comparator();
     $diff = $c->diffTable($oldTable, $keyTable);
     $sql = $this->_platform->getAlterTableSQL($diff);
     $this->assertEquals(array("ALTER TABLE foo ADD PRIMARY KEY (bar)", "CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)"), $sql);
 }
开发者ID:barbondev,项目名称:mysql4-doctrine-driver,代码行数:15,代码来源:MySQL4PlatformTest.php

示例14: testDropPrimaryKeyWithAutoincrementColumn

 /**
  * @group DBAL-464
  */
 public function testDropPrimaryKeyWithAutoincrementColumn()
 {
     $table = new Table("drop_primary_key");
     $table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true));
     $table->addColumn('foo', 'integer', array('primary' => true));
     $table->setPrimaryKey(array('id', 'foo'));
     $this->_sm->dropAndCreateTable($table);
     $diffTable = clone $table;
     $diffTable->dropPrimaryKey();
     $comparator = new Comparator();
     $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
     $table = $this->_sm->listTableDetails("drop_primary_key");
     $this->assertFalse($table->hasPrimaryKey());
     $this->assertFalse($table->getColumn('id')->getAutoincrement());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:18,代码来源:MySqlSchemaManagerTest.php

示例15: define

 /**
  * Defines the table at the specified version
  * 
  * @param Table  $table   Table
  * @param string $version Version
  */
 public function define(Table $table, $version)
 {
     switch (true) {
         // Version 0.1.0
         case version_compare($version, "0.1.0", '>='):
             $table->addColumn('id', 'integer')->setUnsigned(true)->setNotNull(true)->setAutoIncrement(true)->setComment('Timezone ID (local db)');
             $table->addColumn('country_id', 'integer')->setUnsigned(true)->setNotNull(true)->setComment('Country (=> ' . CountryTableDefinition::NAME . '.id)');
             $table->addColumn('code', 'string')->setLength(50)->setNotNull(false)->setComment("Timezone code");
             // Primary key
             $table->setPrimaryKey(['id'], 'PK_GeoTimezone_id');
             // Foriegn keys
             $table->addNamedForeignKeyConstraint('FK_GeoTimezone_country', CountryTableDefinition::NAME, ['country_id'], ['id']);
             // Unique Keys
             $table->addUniqueIndex(['code'], 'UK_GeoTimezone_code');
     }
 }
开发者ID:28karonte,项目名称:JJsGeonamesBundle,代码行数:22,代码来源:TimezoneTableDefinition.php


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