/**
  * @param $name
  *
  * @return Filesystem
  */
 public function create($name)
 {
     switch ($name) {
         case 'local':
             $adapter = new Adapter\Local($this->getParameter('local', 'folder'), $this->getParameter('local', 'create'));
             break;
         case 'sftp_phpseclib':
             $sftp = new \phpseclib\Net\SFTP($this->getParameter('sftp', 'host'), $this->getParameter('sftp', 'port'));
             $sftp->login($this->getParameter('sftp', 'login'), $this->getParameter('sftp', 'password'));
             $adapter = new Adapter\PhpseclibSftp($sftp, $this->getParameter('sftp', 'folder'), true);
             break;
         case 'sftp':
             $configuration = new Ssh\Configuration($this->getParameter('sftp', 'host'), $this->getParameter('sftp', 'port'));
             $authentication = new Ssh\Authentication\Password($this->getParameter('sftp', 'login'), $this->getParameter('sftp', 'password'));
             // for other options, check php-ssh docs
             $session = new Ssh\Session($configuration, $authentication);
             $adapter = new Adapter\Sftp($session->getSftp());
             break;
         case 's3':
             $service = new \Aws\S3\S3Client(array('credentials' => ['key' => $this->getParameter('s3', 'key'), 'secret' => $this->getParameter('s3', 'secret')], 'endpoint' => $this->getParameter('s3', 'endpoint'), 'bucket_endpoint' => $this->getParameter('s3', 'bucket_endpoint'), 'region' => $this->getParameter('s3', 'region'), 'version' => $this->getParameter('s3', 'version')));
             $adapter = new Adapter\AwsS3($service, $this->getParameter('s3', 'bucket'));
             break;
         case 'ftp':
             $adapter = new Adapter\Ftp('/', $this->getParameter('ftp', 'host'), array('username' => $this->getParameter('ftp', 'username'), 'password' => $this->getParameter('ftp', 'password'), 'passive' => $this->getParameter('ftp', 'passive'), 'port' => $this->getParameter('ftp', 'port')));
             break;
         case 'gridfs':
             $client = new MongoClient(sprintf('mongodb://%s:%s', $this->getParameter('gridfs', 'host'), $this->getParameter('gridfs', 'port')));
             $db = $client->selectDB($this->getParameter('gridfs', 'db'));
             $adapter = new Adapter\GridFS(new MongoGridFS($db));
             break;
         case 'mogilefs':
             $adapter = new Adapter\MogileFS('http://*****:*****@%s/%s', $this->getParameter('mysql', 'user'), $this->getParameter('mysql', 'password'), $this->getParameter('mysql', 'host'), $this->getParameter('mysql', 'db'))]);
             $sm = $connection->getSchemaManager();
             $table = new \Doctrine\DBAL\Schema\Table('files');
             if (!$sm->tablesExist(['files'])) {
                 $table = new \Doctrine\DBAL\Schema\Table('files');
                 $table->addColumn('key', 'string');
                 $table->addColumn('content', 'text');
                 $table->addColumn('mtime', 'string');
                 $table->addColumn('checksum', 'string');
                 $sm->createTable($table);
             }
             $adapter = new Adapter\DoctrineDbal($connection, $table->getName());
             break;
         default:
             throw new \RuntimeException(sprintf('Unknown adapter %s', $name));
     }
     return new Filesystem($adapter);
 }
 public function testGenerateTableWithMultiColumnUniqueIndex()
 {
     $table = new \Doctrine\DBAL\Schema\Table('test');
     $table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255));
     $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
     $table->addUniqueIndex(array("foo", "bar"));
     $sql = $this->_platform->getCreateTableSQL($table);
     $this->assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql);
 }
예제 #3
0
 protected function createQueryTestTable()
 {
     $table = new \Doctrine\DBAL\Schema\Table('query_test');
     $table->addColumn('id', 'integer');
     $table->addColumn('val1', 'string');
     $table->addColumn('val2', 'integer');
     try {
         $this->connection->getSchemaManager()->createTable($table);
     } catch (DBALException $e) {
     }
 }
예제 #4
0
 public function setUp()
 {
     parent::setUp();
     try {
         /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
         $table = new \Doctrine\DBAL\Schema\Table("fetch_table");
         $table->addColumn('test_int', 'integer');
         $table->addColumn('test_string', 'string');
         $sm = $this->_conn->getSchemaManager();
         $sm->createTable($table);
         $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo'));
     } catch (\Exception $e) {
     }
 }
예제 #5
0
 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());
 }
 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));
         $sm = $this->_conn->getSchemaManager();
         $sm->createTable($table);
     } catch (\Exception $e) {
     }
     $this->_conn->executeUpdate('DELETE FROM write_table');
 }
예제 #7
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 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 testGenerateTableWithAutoincrement()
 {
     $table = new \Doctrine\DBAL\Schema\Table('autoinc_table');
     $column = $table->addColumn('id', 'integer');
     $column->setAutoincrement(true);
     $this->assertEquals(array('CREATE TABLE autoinc_table (id SERIAL NOT NULL)'), $this->_platform->getCreateTableSQL($table));
 }
예제 #10
0
 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');
 }
예제 #11
0
 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 (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;
     }
 }
예제 #13
0
 public function testGenerateMixedCaseTableCreate()
 {
     $table = new \Doctrine\DBAL\Schema\Table("Foo");
     $table->addColumn("Bar", "integer");
     $sql = $this->_platform->getCreateTableSQL($table);
     $this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) ENGINE = InnoDB', array_shift($sql));
 }
 /**
  * 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);
 }
예제 #15
0
 public function setUp()
 {
     parent::setUp();
     if (self::$generated === false) {
         self::$generated = true;
         /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
         $table = new \Doctrine\DBAL\Schema\Table("write_table");
         $table->addColumn('test_int', 'integer');
         $table->addColumn('test_string', 'string');
         $table->addColumn('test_float', 'float');
         $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_obj', MapType::NAME, array('platformOptions' => $platformOptions));
         $sm = $this->_conn->getSchemaManager();
         $sm->createTable($table);
     }
 }
 public function testCreateFederatedOnTable()
 {
     $table = new \Doctrine\DBAL\Schema\Table("tbl");
     $table->addColumn("id", "integer");
     $table->addOption('azure.federatedOnDistributionName', 'TblId');
     $table->addOption('azure.federatedOnColumnName', 'id');
     $this->assertEquals(array('CREATE TABLE tbl (id INT NOT NULL) FEDERATED ON (TblId = id)'), $this->platform->getCreateTableSQL($table));
 }
예제 #17
0
 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;
     }
 }
예제 #18
0
 public function testStrictMapTableCreationWithSchemaManager()
 {
     $platform = $this->_conn->getDatabasePlatform();
     $table = new \Doctrine\DBAL\Schema\Table('items');
     $objDefinition = array('type' => \Crate\DBAL\Types\MapType::STRICT, 'fields' => array(new \Doctrine\DBAL\Schema\Column('id', \Doctrine\DBAL\Types\Type::getType('integer'), array()), new \Doctrine\DBAL\Schema\Column('name', \Doctrine\DBAL\Types\Type::getType('string'), array())));
     $table->addColumn('object_column', \Crate\DBAL\Types\MapType::NAME, array('platformOptions' => $objDefinition));
     $createFlags = CratePlatform::CREATE_INDEXES | CratePlatform::CREATE_FOREIGNKEYS;
     $sql = $platform->getCreateTableSQL($table, $createFlags);
     $this->assertEquals(array('CREATE TABLE items (object_column OBJECT ( strict ) AS ( id INTEGER, name STRING ))'), $sql);
 }
예제 #19
0
 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');
     }
 }
예제 #20
0
 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);
 }
예제 #22
0
 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']);
 }
 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));
             $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' => 1, 'Test_String' => 'foo  ', 'Test_Null' => null));
         } catch (\Exception $e) {
         }
     }
     return $this->portableConnection;
 }
 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());
         }
     }
 }
예제 #25
0
 /**
  * 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);
     }
 }
예제 #27
0
 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 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']);
 }
 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) {
     }
 }
 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');
         $table2 = new \Doctrine\DBAL\Schema\Table("modify_limit_table2");
         $table2->addColumn('test_int', 'integer');
         $sm = $this->_conn->getSchemaManager();
         $sm->createTable($table);
         $sm->createTable($table2);
         self::$tableCreated = true;
     }
     $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table'));
     $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table2'));
 }