public function setUp() { parent::setUp(); /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $sm = $this->_conn->getSchemaManager(); $table = new \Doctrine\DBAL\Schema\Table("type_conversion"); $table->addColumn('id', 'integer', array('notnull' => false)); $table->addColumn('test_string', 'string', array('notnull' => false)); $table->addColumn('test_boolean', 'boolean', array('notnull' => false)); $table->addColumn('test_bigint', 'bigint', array('notnull' => false)); $table->addColumn('test_smallint', 'bigint', array('notnull' => false)); $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); $table->addColumn('test_datetimetz', 'datetimetz', array('notnull' => false)); $table->addColumn('test_date', 'date', array('notnull' => false)); $table->addColumn('test_time', 'time', array('notnull' => false)); $table->addColumn('test_text', 'text', array('notnull' => false)); $table->addColumn('test_array', 'array', array('notnull' => false)); $table->addColumn('test_object', 'object', array('notnull' => false)); $table->addColumn('test_float', 'float', array('notnull' => false)); $table->addColumn('test_decimal', 'decimal', array('notnull' => false, 'scale' => 2, 'precision' => 10)); $table->setPrimaryKey(array('id')); try { foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $this->_conn->executeQuery($sql); } } catch (\Exception $e) { } }
public function setUp() { parent::setUp(); /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $sm = $this->_conn->getSchemaManager(); if (!$sm->tablesExist(array('type_conversion'))) { $table = new \Doctrine\DBAL\Schema\Table("type_conversion"); $table->addColumn('id', 'integer', array('notnull' => false)); $table->addColumn('test_string', 'string', array('notnull' => false)); $table->addColumn('test_boolean', 'boolean', array('notnull' => false)); $table->addColumn('test_bigint', 'bigint', array('notnull' => false)); $table->addColumn('test_smallint', 'bigint', array('notnull' => false)); $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); $table->addColumn('test_datetimetz', 'datetimetz', array('notnull' => false)); $table->addColumn('test_date', 'date', array('notnull' => false)); $table->addColumn('test_time', 'time', array('notnull' => false)); $table->addColumn('test_text', 'text', array('notnull' => false)); $table->addColumn('test_array', 'array', array('notnull' => false)); $table->addColumn('test_object', 'object', array('notnull' => false)); $table->addColumn('test_float', 'float', array('notnull' => false)); $table->addColumn('test_decimal', 'decimal', array('notnull' => false, 'scale' => 2, 'precision' => 10)); $table->setPrimaryKey(array('id')); $sm->createTable($table); } }
protected function createTableSchema() { $table = new \Doctrine\DBAL\Schema\Table('points'); $table->addColumn('id', 'integer', array('notnull' => true)); $table->addColumn('text', 'text', array('notnull' => true)); $table->addColumn('tsvector', 'tsvector', array('notnull' => true)); $table->addColumn('geometry', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'GEOMETRY', 'srid' => 0)); $table->addColumn('point', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINT', 'srid' => 0)); $table->addColumn('point_2d', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINT', 'srid' => 3785)); $table->addColumn('point_3dz', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINTZ', 'srid' => 3785)); $table->addColumn('point_3dm', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINTM', 'srid' => 3785)); $table->addColumn('point_4d', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINTZM', 'srid' => 3785)); $table->addColumn('point_2d_nullable', 'geometry', array('notnull' => false))->setCustomSchemaOptions(array('geometry_type' => 'POINT', 'srid' => 3785)); $table->addColumn('point_2d_nosrid', 'geometry', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINT', 'srid' => 0)); $table->addColumn('geography', 'geography', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'GEOMETRY', 'srid' => 4326)); $table->addColumn('point_geography_2d', 'geography', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINT', 'srid' => 4326)); $table->addColumn('point_geography_2d_srid', 'geography', array('notnull' => true))->setCustomSchemaOptions(array('geometry_type' => 'POINT', 'srid' => 4326)); $table->addIndex(array('text'), 'idx_text'); $table->addIndex(array('tsvector'), 'idx_text_gist'); $table->addIndex(array('point'), null, array('SPATIAL')); $table->addIndex(array('point_2d'), null, array('SPATIAL')); $table->addIndex(array('point_3dz'), null, array('SPATIAL')); $table->addIndex(array('point_3dm'), null, array('SPATIAL')); $table->addIndex(array('point_4d'), null, array('SPATIAL')); $table->addIndex(array('point_2d_nullable'), null, array('SPATIAL')); $table->addIndex(array('point_2d_nosrid'), null, array('SPATIAL')); $table->addIndex(array('point_geography_2d'), null, array('SPATIAL')); $table->addIndex(array('point_geography_2d_srid'), null, array('SPATIAL')); $table->setPrimaryKey(array('id')); return $table; }
public function testGeneratesTableCreationSql() { $table = new \Doctrine\DBAL\Schema\Table('test'); $table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true)); $table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); $table->setPrimaryKey(array('id')); $sql = $this->_platform->getCreateTableSQL($table); $this->assertEquals($this->getGenerateTableSql(), $sql[0]); }
/** * @group DDC-2387 */ public function testCompositeAssociationKeyDetection() { $product = new \Doctrine\DBAL\Schema\Table('ddc2387_product'); $product->addColumn('id', 'integer'); $product->setPrimaryKey(array('id')); $attributes = new \Doctrine\DBAL\Schema\Table('ddc2387_attributes'); $attributes->addColumn('product_id', 'integer'); $attributes->addColumn('attribute_name', 'string'); $attributes->setPrimaryKey(array('product_id', 'attribute_name')); $attributes->addForeignKeyConstraint('ddc2387_product', array('product_id'), array('product_id')); $metadata = $this->convertToClassMetadata(array($product, $attributes), array()); $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $metadata['Ddc2387Attributes']->generatorType); $this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_AUTO, $metadata['Ddc2387Product']->generatorType); }
public function testDomainsTable() { if ($this->_conn->getDatabasePlatform()->getName() != "postgresql") { $this->markTestSkipped('PostgreSQL only test'); } $table = new \Doctrine\DBAL\Schema\Table("domains"); $table->addColumn('id', 'integer'); $table->addColumn('parent_id', 'integer'); $table->setPrimaryKey(array('id')); $table->addForeignKeyConstraint('domains', array('parent_id'), array('id')); $this->_conn->getSchemaManager()->createTable($table); $table = $this->_conn->getSchemaManager()->listTableDetails('domains'); $this->assertEquals('domains', $table->getName()); }
protected function setUp() { parent::setUp(); if ($this->_conn->getDatabasePlatform()->getName() != 'oracle') { $this->markTestSkipped('OCI8 only test'); } if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) { $this->_conn->executeQuery('DELETE FROM DBAL202'); } else { $table = new \Doctrine\DBAL\Schema\Table('DBAL202'); $table->addColumn('id', 'integer'); $table->setPrimaryKey(array('id')); $this->_conn->getSchemaManager()->createTable($table); } }
public function testListTableWithBinary() { $tableName = 'test_binary_table'; $table = new \Doctrine\DBAL\Schema\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()); }
public function setUp() { parent::setUp(); try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("write_table"); $table->addColumn('test_int', 'integer'); $table->addColumn('test_string', 'string', array('notnull' => false)); $table->setPrimaryKey(array('test_int')); foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $this->_conn->executeQuery($sql); } } catch (\Exception $e) { } $this->_conn->executeUpdate('DELETE FROM write_table'); }
public function setUp() { parent::setUp(); if (self::$generated === false) { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("fetch_table"); $table->addColumn('test_int', 'integer'); $table->addColumn('test_string', 'string'); $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); $table->setPrimaryKey(array('test_int')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10')); self::$generated = true; } }
public function setUp() { parent::setUp(); try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("blob_table"); $table->addColumn('id', 'integer'); $table->addColumn('clobfield', 'text'); $table->addColumn('blobfield', 'blob'); $table->setPrimaryKey(array('id')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); } catch (\Exception $e) { } $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('blob_table')); }
public function setUp() { parent::setUp(); if ($this->_conn->getDatabasePlatform()->getName() == "sqlite") { $this->markTestSkipped('Test does not work on sqlite.'); } try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("master_slave_table"); $table->addColumn('test_int', 'integer'); $table->setPrimaryKey(array('test_int')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); $this->_conn->insert('master_slave_table', array('test_int' => 1)); } catch (\Exception $e) { } }
/** * Do the migration */ public function up() { $container = $this->getContainer(); $table = new Doctrine\DBAL\Schema\Table('target_log'); $table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true)); $table->addColumn('target_type', 'string', array('length' => 64, 'default' => '', 'null' => false, 'comment' => '日志对象类型')); $table->addColumn('target_id', 'integer', array('default' => 0, 'null' => false, 'comment' => '日志对象ID')); $table->addColumn('action', 'string', array('length' => 64, 'default' => '', 'null' => false, 'comment' => '日志行为')); $table->addColumn('level', 'smallint', array('default' => 0, 'null' => false, 'comment' => '日志等级')); $table->addColumn('message', 'text', array('comment' => '日志信息')); $table->addColumn('context', 'text', array('comment' => '日志上下文')); $table->addColumn('user_id', 'integer', array('default' => 0, 'null' => false, 'comment' => '操作人ID')); $table->addColumn('ip', 'string', array('length' => 32, 'default' => '', 'null' => false, 'comment' => '操作人IP')); $table->addColumn('created', 'integer', array('default' => 0, 'null' => false, 'comment' => '创建时间')); $table->setPrimaryKey(array('id')); $container['db']->getSchemaManager()->createTable($table); }
public function setUp() { parent::setUp(); if (!self::$tableCreated) { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("modify_limit_table"); $table->addColumn('test_int', 'integer'); $table->setPrimaryKey(array('test_int')); $table2 = new \Doctrine\DBAL\Schema\Table("modify_limit_table2"); $table2->addColumn('id', 'integer', array('autoincrement' => true)); $table2->addColumn('test_int', 'integer'); $table2->setPrimaryKey(array('id')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); $sm->createTable($table2); self::$tableCreated = true; } }
public function setUp() { parent::setUp(); $platformName = $this->_conn->getDatabasePlatform()->getName(); // This is a MySQL specific test, skip other vendors. if ($platformName != 'mysql') { $this->markTestSkipped(sprintf('Test does not work on %s.', $platformName)); } try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("master_slave_table"); $table->addColumn('test_int', 'integer'); $table->setPrimaryKey(array('test_int')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); } catch (\Exception $e) { } $this->_conn->executeUpdate('DELETE FROM master_slave_table'); $this->_conn->insert('master_slave_table', array('test_int' => 1)); }
public function setUp() { parent::setUp(); if (self::$generated === false) { self::$generated = true; /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $sm = $this->_conn->getSchemaManager(); $table = new \Doctrine\DBAL\Schema\Table("fetch_table"); $table->addColumn('test_int', 'integer'); $table->addColumn('test_string', 'string'); $table->addColumn('test_datetime', 'timestamp', array('notnull' => false)); $table->addColumn('test_array', 'array', array('columnDefinition' => 'ARRAY(STRING)')); $platformOptions = array('type' => MapType::STRICT, 'fields' => array(new Column('id', Type::getType('integer'), array()), new Column('name', Type::getType('string'), array()), new Column('value', Type::getType('float'), array()))); $table->addColumn('test_object', MapType::NAME, array('platformOptions' => $platformOptions)); $table->setPrimaryKey(array('test_int')); $sm->createTable($table); $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => new \DateTime('2010-01-01 10:10:10'), 'test_array' => array('foo', 'bar'), 'test_object' => array('id' => 1, 'name' => 'foo', 'value' => 1.234)), array('integer', 'string', 'timestamp', 'array', 'map')); $this->refresh('fetch_table'); } }
protected function setUp() { parent::setUp(); if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlsrv\Driver) { $this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp'); } try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("blob_table"); $table->addColumn('id', 'integer'); $table->addColumn('clobfield', 'text'); $table->addColumn('blobfield', 'blob'); $table->addColumn('binaryfield', 'binary', array('length' => 50)); $table->setPrimaryKey(array('id')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); } catch (\Exception $e) { } $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('blob_table')); }
public function setUp() { parent::setUp(); try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("caching"); $table->addColumn('test_int', 'integer'); $table->addColumn('test_string', 'string', array('notnull' => false)); $table->setPrimaryKey(array('test_int')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); } catch (\Exception $e) { } $this->_conn->executeUpdate('DELETE FROM caching'); foreach ($this->expectedResult as $row) { $this->_conn->insert('caching', $row); } $config = $this->_conn->getConfiguration(); $config->setSQLLogger($this->sqlLogger = new \Doctrine\DBAL\Logging\DebugStack()); $cache = new \Doctrine\Common\Cache\ArrayCache(); $config->setResultCacheImpl($cache); }
public function testCreateYamlWithForeignKeyFromDatabase() { if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Platform does not support foreign keys.'); } $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar"); $tableB->addColumn('id', 'integer'); $tableB->setPrimaryKey(array('id')); $this->_sm->dropAndCreateTable($tableB); $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz"); $tableA->addColumn('id', 'integer'); $tableA->setPrimaryKey(array('id')); $tableA->addColumn('bar_id', 'integer'); $tableA->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id')); $this->_sm->dropAndCreateTable($tableA); $metadata = $this->extractClassMetadata("DbdriverBaz"); $this->assertArrayNotHasKey('bar', $metadata->fieldMappings); $this->assertArrayHasKey('id', $metadata->fieldMappings); $metadata->associationMappings = \array_change_key_case($metadata->associationMappings, \CASE_LOWER); $this->assertArrayHasKey('bar', $metadata->associationMappings); $this->assertType('Doctrine\\ORM\\Mapping\\OneToOneMapping', $metadata->associationMappings['bar']); }
public function setUp() { parent::setUp(); if (!$this->_conn->getSchemaManager()->tablesExist("ddc1372_foobar")) { try { $table = new \Doctrine\DBAL\Schema\Table("ddc1372_foobar"); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'string'); $table->addColumn('bar', 'string'); $table->setPrimaryKey(array('id')); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); $this->_conn->insert('ddc1372_foobar', array('id' => 1, 'foo' => 1, 'bar' => 1)); $this->_conn->insert('ddc1372_foobar', array('id' => 2, 'foo' => 1, 'bar' => 2)); $this->_conn->insert('ddc1372_foobar', array('id' => 3, 'foo' => 1, 'bar' => 3)); $this->_conn->insert('ddc1372_foobar', array('id' => 4, 'foo' => 1, 'bar' => 4)); $this->_conn->insert('ddc1372_foobar', array('id' => 5, 'foo' => 2, 'bar' => 1)); $this->_conn->insert('ddc1372_foobar', array('id' => 6, 'foo' => 2, 'bar' => 2)); } catch (\Exception $e) { $this->fail($e->getMessage()); } } }
/** * Return Current Migration Status of the database. * * @return MigrationStatus */ public function getCurrentStatus() { $schemaManager = $this->connection->getSchemaManager(); $tables = $schemaManager->listTableNames(); if (!in_array('changelog', $tables)) { $table = new \Doctrine\DBAL\Schema\Table('changelog'); $table->addColumn('change_number', 'integer'); $table->addColumn('complete_dt', 'datetime', array('columnDefinition' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')); $table->addColumn('applied_by', 'string', array('length' => 100)); $table->addcolumn('description', 'string', array('length' => 500)); $table->setPrimaryKey(array('change_number')); $schemaManager->createTable($table); } $allMigrations = $this->getAllMigrations($this->schemaDirectory); $appliedMigrations = $this->getAppliedMigrations(); $applyMigrations = array(); foreach ($allMigrations as $revision => $data) { if (!isset($appliedMigrations[$revision])) { $applyMigrations[$revision] = $data; } } return new MigrationStatus($allMigrations, $appliedMigrations, $applyMigrations); }
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { if (!class_exists($suite->getName())) { return; } if (!self::$booted && self::$logSQL) { self::$booted = true; $app = new \Alchemy\Phrasea\Application(\Alchemy\Phrasea\Application::ENV_TEST); self::$conn = $app['dbal.provider']($app['db.info']($app['db.appbox.info'])); unset($app); self::$conn->connect(); $schema = self::$conn->getSchemaManager(); $tableTest = new \Doctrine\DBAL\Schema\Table("tests"); /* Add some columns to the table */ $tableTest->addColumn("id", "integer", array("unsigned" => true, "autoincrement" => true)); $tableTest->addColumn("test", "string", array("length" => 256)); $tableTest->addColumn("name", "string", array("length" => 256)); $tableTest->addColumn("status", "string", array("length" => 16)); $tableTest->addColumn("duration", "float"); /* Add a primary key */ $tableTest->setPrimaryKey(array("id")); $schema->dropAndCreateTable($tableTest); } }
public function testLoadMetadataWithForeignKeyFromDatabase() { if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Platform does not support foreign keys.'); } $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar"); $tableB->addColumn('id', 'integer'); $tableB->setPrimaryKey(array('id')); $this->_sm->dropAndCreateTable($tableB); $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz"); $tableA->addColumn('id', 'integer'); $tableA->setPrimaryKey(array('id')); $tableA->addColumn('bar_id', 'integer'); $tableA->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id')); $this->_sm->dropAndCreateTable($tableA); $metadatas = $this->extractClassMetadata(array("DbdriverBar", "DbdriverBaz")); $this->assertArrayHasKey('DbdriverBaz', $metadatas); $bazMetadata = $metadatas['DbdriverBaz']; $this->assertArrayNotHasKey('barId', $bazMetadata->fieldMappings, "The foreign Key field should not be inflected as 'barId' field, its an association."); $this->assertArrayHasKey('id', $bazMetadata->fieldMappings); $bazMetadata->associationMappings = \array_change_key_case($bazMetadata->associationMappings, \CASE_LOWER); $this->assertArrayHasKey('bar', $bazMetadata->associationMappings); $this->assertEquals(ClassMetadataInfo::MANY_TO_ONE, $bazMetadata->associationMappings['bar']['type']); }
/** * @param integer $portabilityMode * @param integer $case * @return Connection */ private function getPortableConnection($portabilityMode = \Doctrine\DBAL\Portability\Connection::PORTABILITY_ALL, $case = \PDO::CASE_LOWER) { if (!$this->portableConnection) { $params = $this->_conn->getParams(); $params['wrapperClass'] = 'Doctrine\\DBAL\\Portability\\Connection'; $params['portability'] = $portabilityMode; $params['fetch_case'] = $case; $this->portableConnection = DriverManager::getConnection($params, $this->_conn->getConfiguration(), $this->_conn->getEventManager()); try { /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ $table = new \Doctrine\DBAL\Schema\Table("portability_table"); $table->addColumn('Test_Int', 'integer'); $table->addColumn('Test_String', 'string', array('fixed' => true, 'length' => 32)); $table->addColumn('Test_Null', 'string', array('notnull' => false)); $table->setPrimaryKey(array('Test_Int')); $sm = $this->portableConnection->getSchemaManager(); $sm->createTable($table); $this->portableConnection->insert('portability_table', array('Test_Int' => 1, 'Test_String' => 'foo', 'Test_Null' => '')); $this->portableConnection->insert('portability_table', array('Test_Int' => 2, 'Test_String' => 'foo ', 'Test_Null' => null)); } catch (\Exception $e) { } } return $this->portableConnection; }
/** * @group DDC-1845 */ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() { $table = new \Doctrine\DBAL\Schema\Table('test'); $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true)); $table->setPrimaryKey(array('"like"')); $createTableSQL = $this->_platform->getCreateTableSQL($table); $this->assertEquals('CREATE TABLE test ("like" INTEGER NOT NULL, PRIMARY KEY("like"))', $createTableSQL[0]); $this->assertEquals('ALTER TABLE test ADD PRIMARY KEY ("like")', $this->_platform->getCreatePrimaryKeySQL($table->getIndex('primary'), 'test')); }
/** * @group DBAL-220 */ public function testCreateNonClusteredPrimaryKeyInTable() { $table = new \Doctrine\DBAL\Schema\Table("tbl"); $table->addColumn("id", "integer"); $table->setPrimaryKey(array("id")); $table->getIndex('primary')->addFlag('nonclustered'); $this->assertEquals(array('CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'), $this->_platform->getCreateTableSQL($table)); }
protected function getTestMaxColsTable($name, $options = array()) { $maxCols = 16; $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $columnNames = array(); for ($i = 0; $i < $maxCols; $i++) { $columnName = 'col' . $i; $table->addColumn($columnName, 'integer'); $columnNames[] = $columnName; } $table->setPrimaryKey($columnNames); return $table; }
protected function getTestTable($name, $options=array()) { $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer', array('notnull' => true)); $table->setPrimaryKey(array('id')); $table->addColumn('test', 'string', array('length' => 255)); $table->addColumn('foreign_key_test', 'integer'); return $table; }
public function testCreateTableColumnTypeComments() { $table = new \Doctrine\DBAL\Schema\Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('data', 'array'); $table->setPrimaryKey(array('id')); $this->assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table)); }
/** * @group DBAL-75 */ public function testTableWithSchema() { $this->_conn->exec('CREATE SCHEMA nested'); $nestedRelatedTable = new \Doctrine\DBAL\Schema\Table('nested.schemarelated'); $column = $nestedRelatedTable->addColumn('id', 'integer'); $column->setAutoincrement(true); $nestedRelatedTable->setPrimaryKey(array('id')); $nestedSchemaTable = new \Doctrine\DBAL\Schema\Table('nested.schematable'); $column = $nestedSchemaTable->addColumn('id', 'integer'); $column->setAutoincrement(true); $nestedSchemaTable->setPrimaryKey(array('id')); $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, array('id'), array('id')); $this->_sm->createTable($nestedRelatedTable); $this->_sm->createTable($nestedSchemaTable); $tables = $this->_sm->listTableNames(); $this->assertContains('nested.schematable', $tables, "The table should be detected with its non-public schema."); $nestedSchemaTable = $this->_sm->listTableDetails('nested.schematable'); $this->assertTrue($nestedSchemaTable->hasColumn('id')); $this->assertEquals(array('id'), $nestedSchemaTable->getPrimaryKey()->getColumns()); $relatedFks = $nestedSchemaTable->getForeignKeys(); $this->assertEquals(1, count($relatedFks)); $relatedFk = array_pop($relatedFks); $this->assertEquals("nested.schemarelated", $relatedFk->getForeignTableName()); }