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


PHP AbstractSchemaManager::createTable方法代码示例

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


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

示例1: testCommentStringsAreQuoted

 public function testCommentStringsAreQuoted()
 {
     if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && $this->_conn->getDatabasePlatform()->getName() != 'mssql') {
         $this->markTestSkipped('Database does not support column comments.');
     }
     $table = new Table('my_table');
     $table->addColumn('id', 'integer', array('comment' => "It's a comment with a quote"));
     $table->setPrimaryKey(array('id'));
     $this->_sm->createTable($table);
     $columns = $this->_sm->listTableColumns("my_table");
     $this->assertEquals("It's a comment with a quote", $columns['id']->getComment());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:12,代码来源:SchemaManagerFunctionalTestCase.php

示例2: testAutoincrementDetection

 public function testAutoincrementDetection()
 {
     if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) {
         $this->markTestSkipped('This test is only supported on platforms that have autoincrement');
     }
     $table = new \Doctrine\DBAL\Schema\Table('test_autoincrement');
     $table->setSchemaConfig($this->_sm->createSchemaConfig());
     $table->addColumn('id', 'integer', array('autoincrement' => true));
     $table->setPrimaryKey(array('id'));
     $this->_sm->createTable($table);
     $inferredTable = $this->_sm->listTableDetails('test_autoincrement');
     $this->assertTrue($inferredTable->hasColumn('id'));
     $this->assertTrue($inferredTable->getColumn('id')->getAutoincrement());
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:14,代码来源:SchemaManagerFunctionalTestCase.php

示例3: createModel

 /**
  * Creates database table represented by the model.
  *
  * @param Model $model
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
  */
 public function createModel($model)
 {
     $schema = $this->schemaManager->createSchema();
     $tableDef = $schema->createTable($model->meta->dbTable);
     // this assumes fields set_from_name has been invoked
     $primaryKeyFields = [];
     $unique_fields = [];
     $indexes = [];
     /** @var $field Field */
     /** @var $field ForeignKey */
     foreach ($model->meta->localFields as $fname => $field) {
         $colName = $field->getColumnName();
         $type = $field->dbType($this->connection);
         // if we don't have a type stop
         if (empty($type)) {
             continue;
         }
         if ($field->primaryKey) {
             $primaryKeyFields[] = $model->meta->primaryKey->getColumnName();
         } elseif ($field->isUnique()) {
             $unique_fields[] = $colName;
         } elseif ($field->dbIndex) {
             $indexes[] = $colName;
         }
         $tableDef->addColumn($colName, $type, $this->getDoctrineColumnOptions($field));
         if ($field->isRelation && $field->relation && $field->dbConstraint) {
             $relField = $field->getRelatedField();
             $tableDef->addForeignKeyConstraint($relField->scopeModel->meta->dbTable, [$field->getColumnName()], [$relField->getColumnName()]);
         }
     }
     // create the primary key
     $tableDef->setPrimaryKey($primaryKeyFields);
     // add index constraint
     if (!empty($indexes)) {
         $tableDef->addIndex($indexes);
     }
     // add unique constraint
     if (!empty($unique_fields)) {
         $tableDef->addUniqueIndex($unique_fields);
     }
     $this->schemaManager->createTable($tableDef);
     // many to many
     /** @var $relationField ManyToManyField */
     foreach ($model->meta->localManyToMany as $name => $relationField) {
         if ($relationField->manyToMany && $relationField->relation->through->meta->autoCreated) {
             $this->createModel($relationField->relation->through);
         }
     }
 }
开发者ID:eddmash,项目名称:powerorm,代码行数:58,代码来源:SchemaEditor.php

示例4: testListForeignKeysComposite

 public function testListForeignKeysComposite()
 {
     if (!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('Does not support foreign key constraints.');
     }
     $this->_sm->createTable($this->getTestTable('test_create_fk3'));
     $this->_sm->createTable($this->getTestCompositeTable('test_create_fk4'));
     $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id', 'foreign_key_test'), 'test_create_fk4', array('id', 'other_id'), 'foreign_key_test_fk');
     $this->_sm->createForeignKey($foreignKey, 'test_create_fk3');
     $fkeys = $this->_sm->listTableForeignKeys('test_create_fk3');
     $this->assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key.");
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $fkeys[0]);
     $this->assertEquals(array('id', 'foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
     $this->assertEquals(array('id', 'other_id'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:15,代码来源:SchemaManagerFunctionalTestCase.php

示例5: testAutomaticallyAppendCommentOnMarkedColumns

 /**
  * @group DBAL-42
  */
 public function testAutomaticallyAppendCommentOnMarkedColumns()
 {
     if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement()) {
         $this->markTestSkipped('Database does not support column comments.');
     }
     $table = new \Doctrine\DBAL\Schema\Table('column_comment_test2');
     $table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
     $table->addColumn('obj', 'object', array('comment' => 'This is a comment'));
     $table->addColumn('arr', 'array', array('comment' => 'This is a comment'));
     $table->setPrimaryKey(array('id'));
     $this->_sm->createTable($table);
     $columns = $this->_sm->listTableColumns("column_comment_test2");
     $this->assertEquals(3, count($columns));
     $this->assertEquals('This is a comment', $columns['id']->getComment());
     $this->assertEquals('This is a comment', $columns['obj']->getComment(), "The Doctrine2 Typehint should be stripped from comment.");
     $this->assertInstanceOf('Doctrine\\DBAL\\Types\\ObjectType', $columns['obj']->getType(), "The Doctrine2 should be detected from comment hint.");
     $this->assertEquals('This is a comment', $columns['arr']->getComment(), "The Doctrine2 Typehint should be stripped from comment.");
     $this->assertInstanceOf('Doctrine\\DBAL\\Types\\ArrayType', $columns['arr']->getType(), "The Doctrine2 should be detected from comment hint.");
 }
开发者ID:rodmen,项目名称:dbal,代码行数:22,代码来源:SchemaManagerFunctionalTestCase.php

示例6: testListTableIndexes

 public function testListTableIndexes()
 {
     $table = $this->getTestTable('list_table_indexes_test');
     $table->addUniqueIndex(array('test'), 'test_index_name');
     $table->addIndex(array('id', 'test'), 'test_composite_idx');
     $this->_sm->createTable($table);
     $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
     $this->assertEquals(3, count($tableIndexes));
     $this->assertEquals(array('id'), array_map('strtolower', $tableIndexes['primary']->getColumns()));
     $this->assertTrue($tableIndexes['primary']->isUnique());
     $this->assertTrue($tableIndexes['primary']->isPrimary());
     $this->assertEquals('test_index_name', $tableIndexes['test_index_name']->getName());
     $this->assertEquals(array('test'), array_map('strtolower', $tableIndexes['test_index_name']->getColumns()));
     $this->assertTrue($tableIndexes['test_index_name']->isUnique());
     $this->assertFalse($tableIndexes['test_index_name']->isPrimary());
     $this->assertEquals('test_composite_idx', $tableIndexes['test_composite_idx']->getName());
     $this->assertEquals(array('id', 'test'), array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns()));
     $this->assertFalse($tableIndexes['test_composite_idx']->isUnique());
     $this->assertFalse($tableIndexes['test_composite_idx']->isPrimary());
 }
开发者ID:andreia,项目名称:doctrine,代码行数:20,代码来源:SchemaManagerFunctionalTestCase.php

示例7: createTable

 /**
  * Creates a new database table.
  *
  * @param string  $table
  * @param \Closure $callback
  */
 public function createTable($table, \Closure $callback)
 {
     $table = $this->schema->createTable($this->replacePrefix($table));
     $callback($table);
     $this->manager->createTable($table);
 }
开发者ID:enyaku,项目名称:myGoogleMapsApiV3Test,代码行数:12,代码来源:Utility.php

示例8: createTable

 private function createTable()
 {
     $table = new Table(self::TABLE, array(new Column($this->keyColumn, Type::getType(Type::STRING)), new Column($this->valueColumn, Type::getType(Type::TARRAY))));
     $table->setPrimaryKey(array($this->keyColumn));
     $this->schemaManager->createTable($table);
 }
开发者ID:alinnflorinn,项目名称:CraueFormFlowBundle,代码行数:6,代码来源:DoctrineStorage.php

示例9: createTable

 /**
  * @param AbstractSchemaManager $schemaM
  * @param Schema                $schema
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
  */
 public function createTable($schemaM, $schema)
 {
     if ($schemaM->tablesExist('artists')) {
         $schemaM->dropTable('artists');
     }
     if ($schemaM->tablesExist('user')) {
         $schemaM->dropTable('user');
     }
     echo 'Tables :: ';
     $UTable = $schema->createTable('user');
     $UTable->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
     $UTable->addColumn('name', 'string', ['length' => 60]);
     $UTable->setPrimaryKey(['id']);
     $myTable = $schema->createTable('artists');
     $myTable->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
     $myTable->addColumn('user_id', 'integer', ['unsigned' => true]);
     $myTable->addColumn('name', 'string', ['length' => 60]);
     $myTable->setPrimaryKey(['id']);
     $myTable->addForeignKeyConstraint($UTable, array('user_id'), array('id'), array('onUpdate' => 'CASCADE'));
     $schemaM->createTable($UTable);
     $schemaM->createTable($myTable);
 }
开发者ID:eddmash,项目名称:powerorm,代码行数:30,代码来源:Testdb.php


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