Commit 0d572181 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix more occurances of the extending Test bug, "reactivating" a total of 200...

Fix more occurances of the extending Test bug, "reactivating" a total of 200 tests. SQLAnywhere is missing and is a bit more annyoing to fix, because of a deep inheritance hierachy.
parent a90a4c50
<?php
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Index;
abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
{
public function testModifyLimitQueryWitoutLimit()
{
$sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null , 10);
$this->assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql);
}
public function testGenerateMixedCaseTableCreate()
{
$table = new Table("Foo");
$table->addColumn("Bar", "integer");
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql));
}
public function getGenerateTableSql()
{
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB';
}
public function getGenerateTableWithMultiColumnUniqueIndexSql()
{
return array(
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
public function getGenerateAlterTableSql()
{
return array(
"ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"
);
}
public function testGeneratesSqlSnippets()
{
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
$this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Quote character is not correct');
$this->assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct');
}
public function testGeneratesTransactionsCommands()
{
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED),
''
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$this->assertEquals('SHOW DATABASES', $this->_platform->getListDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
public function testGeneratesTypeDeclarationForStrings()
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'VARCHAR(255)',
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}
public function testPrefersIdentityColumns()
{
$this->assertTrue($this->_platform->prefersIdentityColumns());
}
public function testSupportsIdentityColumns()
{
$this->assertTrue($this->_platform->supportsIdentityColumns());
}
public function testDoesSupportSavePoints()
{
$this->assertTrue($this->_platform->supportsSavepoints());
}
public function getGenerateIndexSql()
{
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
}
public function getGenerateUniqueIndexSql()
{
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
}
public function getGenerateForeignKeySql()
{
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
}
/**
* @group DBAL-126
*/
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);
}
public function testModifyLimitQuery()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
}
public function testModifyLimitQueryWithEmptyOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
$this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
}
/**
* @group DDC-118
*/
public function testGetDateTimeTypeDeclarationSql()
{
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false)));
$this->assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array()));
}
public function getCreateTableColumnCommentsSQL()
{
return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
}
public function getAlterTableColumnCommentsSQL()
{
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
}
public function getCreateTableColumnTypeCommentsSQL()
{
return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
}
/**
* @group DBAL-237
*/
public function testChangeIndexWithForeignKeys()
{
$index = new Index("idx", array("col"), false);
$unique = new Index("uniq", array("col"), true);
$diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index));
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql);
$diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique));
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql);
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
protected function getQuotedColumnInIndexSQL()
{
return array(
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
protected function getQuotedColumnInForeignKeySQL()
{
return array(
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)',
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)',
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)',
);
}
public function testCreateTableWithFulltextIndex()
{
$table = new Table('fulltext_table');
$table->addOption('engine', 'MyISAM');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'fulltext_text');
$index = $table->getIndex('fulltext_text');
$index->addFlag('fulltext');
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
}
public function testClobTypeDeclarationSQL()
{
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1)));
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255)));
$this->assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256)));
$this->assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535)));
$this->assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536)));
$this->assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215)));
$this->assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216)));
$this->assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array()));
}
public function testBlobTypeDeclarationSQL()
{
$this->assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1)));
$this->assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255)));
$this->assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256)));
$this->assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535)));
$this->assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536)));
$this->assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215)));
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216)));
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array()));
}
/**
* @group DBAL-400
*/
public function testAlterTableAddPrimaryKey()
{
$table = new Table('alter_table_add_pk');
$table->addColumn('id', 'integer');
$table->addColumn('foo', 'integer');
$table->addIndex(array('id'), 'idx_id');
$comparator = new Comparator();
$diffTable = clone $table;
$diffTable->dropIndex('idx_id');
$diffTable->setPrimaryKey(array('id'));
$this->assertEquals(
array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
/**
* @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->addColumn('bar', 'integer');
$table->setPrimaryKey(array('id', 'foo'));
$comparator = new Comparator();
$diffTable = clone $table;
$diffTable->dropPrimaryKey();
$this->assertEquals(
array(
'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL',
'ALTER TABLE drop_primary_key DROP PRIMARY KEY'
),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
/**
* @group DBAL-586
*/
public function testAddAutoIncrementPrimaryKey()
{
$keyTable = new Table("foo");
$keyTable->addColumn("id", "integer", array('autoincrement' => true));
$keyTable->addColumn("baz", "string");
$keyTable->setPrimaryKey(array("id"));
$oldTable = new Table("foo");
$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 id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)",
), $sql);
}
public function testNamedPrimaryKey()
{
$diff = new TableDiff('mytable');
$diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true);
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array(
"ALTER TABLE mytable DROP PRIMARY KEY",
"ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $sql);
}
public function testInitializesDoctrineTypeMappings()
{
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary'));
}
protected function getBinaryMaxLength()
{
return 65535;
}
public function testReturnsBinaryTypeDeclarationSQL()
{
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
$this->assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65535)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65536)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777215)));
$this->assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777216)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
$this->assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65536)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777215)));
$this->assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777216)));
}
public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines()
{
$table = new Table("foreign_table");
$table->addColumn('id', 'integer');
$table->addColumn('fk_id', 'integer');
$table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
$table->setPrimaryKey(array('id'));
$table->addOption('engine', 'MyISAM');
$this->assertSame(
array('CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'),
$this->_platform->getCreateTableSQL(
$table,
AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
)
);
$table = clone $table;
$table->addOption('engine', 'InnoDB');
$this->assertSame(
array(
'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)'
),
$this->_platform->getCreateTableSQL(
$table,
AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
)
);
}
public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines()
{
$table = new Table("foreign_table");
$table->addColumn('id', 'integer');
$table->addColumn('fk_id', 'integer');
$table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
$table->setPrimaryKey(array('id'));
$table->addOption('engine', 'MyISAM');
$addedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add'));
$changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change'));
$removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove'));
$tableDiff = new TableDiff('foreign_table');
$tableDiff->fromTable = $table;
$tableDiff->addedForeignKeys = $addedForeignKeys;
$tableDiff->changedForeignKeys = $changedForeignKeys;
$tableDiff->removedForeignKeys = $removedForeignKeys;
$this->assertEmpty($this->_platform->getAlterTableSQL($tableDiff));
$table->addOption('engine', 'InnoDB');
$tableDiff = new TableDiff('foreign_table');
$tableDiff->fromTable = $table;
$tableDiff->addedForeignKeys = $addedForeignKeys;
$tableDiff->changedForeignKeys = $changedForeignKeys;
$tableDiff->removedForeignKeys = $removedForeignKeys;
$this->assertSame(
array(
'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove',
'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change',
'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)',
'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)',
),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* @group DBAL-234
*/
protected function getAlterTableRenameIndexSQL()
{
return array(
'DROP INDEX idx_foo ON mytable',
'CREATE INDEX idx_bar ON mytable (id)',
);
}
/**
* @group DBAL-234
*/
protected function getQuotedAlterTableRenameIndexSQL()
{
return array(
'DROP INDEX `create` ON `table`',
'CREATE INDEX `select` ON `table` (id)',
'DROP INDEX `foo` ON `table`',
'CREATE INDEX `bar` ON `table` (id)',
);
}
}
<?php
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Type;
abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase
{
public function getGenerateTableSql()
{
return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test NVARCHAR(255), PRIMARY KEY (id))';
}
public function getGenerateTableWithMultiColumnUniqueIndexSql()
{
return array(
'CREATE TABLE test (foo NVARCHAR(255), bar NVARCHAR(255))',
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL'
);
}
public function getGenerateAlterTableSql()
{
return array(
'ALTER TABLE mytable ADD quota INT',
'ALTER TABLE mytable DROP COLUMN foo',
'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) NOT NULL',
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_78240498 DEFAULT 'def' FOR baz",
'ALTER TABLE mytable ALTER COLUMN bloo BIT NOT NULL',
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_CECED971 DEFAULT '0' FOR bloo",
"sp_RENAME 'mytable', 'userlist'",
"DECLARE @sql NVARCHAR(MAX) = N''; " .
"SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " .
"+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''OBJECT'';' " .
"FROM sys.default_constraints dc " .
"JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " .
"WHERE tbl.name = 'userlist';" .
"EXEC sp_executesql @sql"
);
}
/**
* @expectedException Doctrine\DBAL\DBALException
*/
public function testDoesNotSupportRegexp()
{
$this->_platform->getRegexpExpression();
}
public function testGeneratesSqlSnippets()
{
$this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
$this->assertEquals('(column1 + column2 + column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
}
public function testGeneratesTransactionsCommands()
{
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$dropDatabaseExpectation = 'DROP DATABASE foobar';
$this->assertEquals('SELECT * FROM SYS.DATABASES', $this->_platform->getListDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT IDENTITY',
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT IDENTITY',
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
public function testGeneratesTypeDeclarationsForStrings()
{
$this->assertEquals(
'NCHAR(10)',
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'NVARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'NVARCHAR(255)',
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
$this->assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL(array()));
$this->assertSame(
'VARCHAR(MAX)',
$this->_platform->getClobTypeDeclarationSQL(array('length' => 5, 'fixed' => true))
);
}
public function testPrefersIdentityColumns()
{
$this->assertTrue($this->_platform->prefersIdentityColumns());
}
public function testSupportsIdentityColumns()
{
$this->assertTrue($this->_platform->supportsIdentityColumns());
}
public function testSupportsSchemas()
{
$this->assertTrue($this->_platform->supportsSchemas());
}
public function testDoesNotSupportSavePoints()
{
$this->assertTrue($this->_platform->supportsSavepoints());
}
public function getGenerateIndexSql()
{
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
}
public function getGenerateUniqueIndexSql()
{
return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL';
}
public function getGenerateForeignKeySql()
{
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
}
public function testModifyLimitQuery()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithEmptyOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithOffset()
{
if ( ! $this->_platform->supportsLimitOffset()) {
$this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName()));
}
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
}
public function testModifyLimitQueryWithAscOrderBy()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username ASC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithDescOrderBy()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithMultipleOrderBy()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC, usereamil ASC', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC, usereamil ASC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithSubSelect()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM (SELECT u.id as uid, u.name as uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithSubSelectAndOrder()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC) dctrn_result', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY u.name DESC) AS doctrine_rownum FROM (SELECT u.id as uid, u.name as uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY name DESC) AS doctrine_rownum FROM (SELECT u.id, u.name) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithSubSelectAndMultipleOrder()
{
if ( ! $this->_platform->supportsLimitOffset()) {
$this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName()));
}
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY u.name DESC, id ASC) AS doctrine_rownum FROM (SELECT u.id as uid, u.name as uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY u.name DESC, id ASC) AS doctrine_rownum FROM (SELECT u.id uid, u.name uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY name DESC, id ASC) AS doctrine_rownum FROM (SELECT u.id, u.name) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
}
public function testModifyLimitQueryWithFromColumnNames()
{
$sql = $this->_platform->modifyLimitQuery('SELECT a.fromFoo, fromBar FROM foo', 10);
$this->assertEquals('SELECT * FROM (SELECT a.fromFoo, fromBar, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM foo) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
/**
* @group DDC-2470
*/
public function testModifyLimitQueryWithOrderByClause()
{
if ( ! $this->_platform->supportsLimitOffset()) {
$this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName()));
}
$sql = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2 FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ? ORDER BY m0_.FECHAINICIO DESC';
$expected = 'SELECT * FROM (SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2, ROW_NUMBER() OVER (ORDER BY m0_.FECHAINICIO DESC) AS doctrine_rownum FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ?) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15';
$actual = $this->_platform->modifyLimitQuery($sql, 10, 5);
$this->assertEquals($expected, $actual);
}
/**
* @group DDC-1360
*/
public function testQuoteIdentifier()
{
$this->assertEquals('[fo][o]', $this->_platform->quoteIdentifier('fo]o'));
$this->assertEquals('[test]', $this->_platform->quoteIdentifier('test'));
$this->assertEquals('[test].[test]', $this->_platform->quoteIdentifier('test.test'));
}
/**
* @group DDC-1360
*/
public function testQuoteSingleIdentifier()
{
$this->assertEquals('[fo][o]', $this->_platform->quoteSingleIdentifier('fo]o'));
$this->assertEquals('[test]', $this->_platform->quoteSingleIdentifier('test'));
$this->assertEquals('[test.test]', $this->_platform->quoteSingleIdentifier('test.test'));
}
/**
* @group DBAL-220
*/
public function testCreateClusteredIndex()
{
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'));
$idx->addFlag('clustered');
$this->assertEquals('CREATE CLUSTERED INDEX idx ON tbl (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl'));
}
/**
* @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));
}
/**
* @group DBAL-220
*/
public function testCreateNonClusteredPrimaryKey()
{
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true);
$idx->addFlag('nonclustered');
$this->assertEquals('ALTER TABLE tbl ADD PRIMARY KEY NONCLUSTERED (id)', $this->_platform->getCreatePrimaryKeySQL($idx, 'tbl'));
}
public function testAlterAddPrimaryKey()
{
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true);
$this->assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl'));
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))',
);
}
protected function getQuotedColumnInIndexSQL()
{
return array(
'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL)',
'CREATE INDEX IDX_22660D028FD6E0FB ON [quoted] ([create])',
);
}
protected function getQuotedColumnInForeignKeySQL()
{
return array(
'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, foo NVARCHAR(255) NOT NULL, [bar] NVARCHAR(255) NOT NULL)',
'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ([create], foo, [bar]) REFERENCES [foreign] ([create], bar, [foo-bar])',
'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ([create], foo, [bar]) REFERENCES foo ([create], bar, [foo-bar])',
'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ([create], foo, [bar]) REFERENCES [foo-bar] ([create], bar, [foo-bar])',
);
}
public function testGetCreateSchemaSQL()
{
$schemaName = 'schema';
$sql = $this->_platform->getCreateSchemaSQL($schemaName);
$this->assertEquals('CREATE SCHEMA ' . $schemaName, $sql);
}
public function testSchemaNeedsCreation()
{
$schemaNames = array(
'dbo' => false,
'schema' => true,
);
foreach ($schemaNames as $name => $expected) {
$actual = $this->_platform->schemaNeedsCreation($name);
$this->assertEquals($expected, $actual);
}
}
/**
* @group DBAL-543
*/
public function getCreateTableColumnCommentsSQL()
{
return array(
"CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))",
"EXEC sp_addextendedproperty N'MS_Description', N'This is a comment', N'SCHEMA', dbo, N'TABLE', test, N'COLUMN', id",
);
}
/**
* @group DBAL-543
*/
public function getAlterTableColumnCommentsSQL()
{
return array(
"ALTER TABLE mytable ADD quota INT NOT NULL",
"EXEC sp_addextendedproperty N'MS_Description', N'A comment', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', quota",
// todo
//"EXEC sp_addextendedproperty N'MS_Description', N'B comment', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', baz",
);
}
/**
* @group DBAL-543
*/
public function getCreateTableColumnTypeCommentsSQL()
{
return array(
"CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', test, N'COLUMN', data",
);
}
/**
* @group DBAL-543
*/
public function testGeneratesCreateTableSQLWithColumnComments()
{
$table = new Table('mytable');
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('comment_null', 'integer', array('comment' => null));
$table->addColumn('comment_false', 'integer', array('comment' => false));
$table->addColumn('comment_empty_string', 'integer', array('comment' => ''));
$table->addColumn('comment_integer_0', 'integer', array('comment' => 0));
$table->addColumn('comment_float_0', 'integer', array('comment' => 0.0));
$table->addColumn('comment_string_0', 'integer', array('comment' => '0'));
$table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!'));
$table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!'));
$table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!'));
$table->addColumn('commented_type', 'object');
$table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.'));
$table->setPrimaryKey(array('id'));
$this->assertEquals(
array(
"CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_integer_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_float_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_string_0",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz you!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for explicitely quoted columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [comment_quoted]",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for reserved keyword columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [create]",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine array type.(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type_with_comment",
),
$this->_platform->getCreateTableSQL($table)
);
}
/**
* @group DBAL-543
*/
public function testGeneratesAlterTableSQLWithColumnComments()
{
$table = new Table('mytable');
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('comment_null', 'integer', array('comment' => null));
$table->addColumn('comment_false', 'integer', array('comment' => false));
$table->addColumn('comment_empty_string', 'integer', array('comment' => ''));
$table->addColumn('comment_integer_0', 'integer', array('comment' => 0));
$table->addColumn('comment_float_0', 'integer', array('comment' => 0.0));
$table->addColumn('comment_string_0', 'integer', array('comment' => '0'));
$table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!'));
$table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!'));
$table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!'));
$table->addColumn('commented_type', 'object');
$table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.'));
$table->setPrimaryKey(array('id'));
$tableDiff = new TableDiff('mytable');
$tableDiff->fromTable = $table;
$tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer'));
$tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null));
$tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false));
$tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => ''));
$tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0));
$tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0));
$tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0'));
$tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine'));
$tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez'));
$tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666'));
$tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object'));
$tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666'));
$tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!'));
// Add comment to non-commented column.
$tableDiff->changedColumns['id'] = new ColumnDiff(
'id',
new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')),
array('comment'),
new Column('id', Type::getType('integer'), array('autoincrement' => true))
);
// Remove comment from null-commented column.
$tableDiff->changedColumns['comment_null'] = new ColumnDiff(
'comment_null',
new Column('comment_null', Type::getType('string')),
array('type'),
new Column('comment_null', Type::getType('integer'), array('comment' => null))
);
// Add comment to false-commented column.
$tableDiff->changedColumns['comment_false'] = new ColumnDiff(
'comment_false',
new Column('comment_false', Type::getType('integer'), array('comment' => 'false')),
array('comment'),
new Column('comment_false', Type::getType('integer'), array('comment' => false))
);
// Change type to custom type from empty string commented column.
$tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff(
'comment_empty_string',
new Column('comment_empty_string', Type::getType('object')),
array('type'),
new Column('comment_empty_string', Type::getType('integer'), array('comment' => ''))
);
// Change comment to false-comment from zero-string commented column.
$tableDiff->changedColumns['comment_string_0'] = new ColumnDiff(
'comment_string_0',
new Column('comment_string_0', Type::getType('integer'), array('comment' => false)),
array('comment'),
new Column('comment_string_0', Type::getType('integer'), array('comment' => '0'))
);
// Remove comment from regular commented column.
$tableDiff->changedColumns['comment'] = new ColumnDiff(
'comment',
new Column('comment', Type::getType('integer')),
array('comment'),
new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!'))
);
// Change comment and change type to custom type from regular commented column.
$tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff(
'`comment_quoted`',
new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')),
array('comment', 'type'),
new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!'))
);
// Remove comment and change type to custom type from regular commented column.
$tableDiff->changedColumns['create'] = new ColumnDiff(
'create',
new Column('create', Type::getType('object')),
array('comment', 'type'),
new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!'))
);
// Add comment and change custom type to regular type from non-commented column.
$tableDiff->changedColumns['commented_type'] = new ColumnDiff(
'commented_type',
new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')),
array('comment', 'type'),
new Column('commented_type', Type::getType('object'))
);
// Remove comment from commented custom type column.
$tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff(
'commented_type_with_comment',
new Column('commented_type_with_comment', Type::getType('array')),
array('comment'),
new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.'))
);
$tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0));
$this->assertEquals(
array(
// Renamed columns.
"sp_RENAME 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'",
// Added columns.
"ALTER TABLE mytable ADD added_comment_none INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_null INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_false INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL",
"ALTER TABLE mytable ADD added_comment INT NOT NULL",
"ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL",
"ALTER TABLE mytable ADD [select] INT NOT NULL",
"ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable DROP COLUMN comment_integer_0",
"ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL",
// Renamed columns.
"ALTER TABLE mytable ALTER COLUMN comment_double_0 NUMERIC(10, 0) NOT NULL",
// Added columns.
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment_integer_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment_float_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment_string_0",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment",
"EXEC sp_addextendedproperty N'MS_Description', N'rulez', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [added_comment_quoted]",
"EXEC sp_addextendedproperty N'MS_Description', N'666', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [select]",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_commented_type",
"EXEC sp_addextendedproperty N'MS_Description', N'666(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_commented_type_with_comment",
// Changed columns.
"EXEC sp_addextendedproperty N'MS_Description', N'primary', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', id",
"EXEC sp_addextendedproperty N'MS_Description', N'false', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_false",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_empty_string",
"EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_string_0",
"EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment",
"EXEC sp_updateextendedproperty N'MS_Description', N'Doctrine array.(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [comment_quoted]",
"EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [create]",
"EXEC sp_updateextendedproperty N'MS_Description', N'foo', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type",
"EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type_with_comment",
),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* @group DBAL-122
*/
public function testInitializesDoctrineTypeMappings()
{
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('bigint'));
$this->assertSame('bigint', $this->_platform->getDoctrineTypeMapping('bigint'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('numeric'));
$this->assertSame('decimal', $this->_platform->getDoctrineTypeMapping('numeric'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('bit'));
$this->assertSame('boolean', $this->_platform->getDoctrineTypeMapping('bit'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallint'));
$this->assertSame('smallint', $this->_platform->getDoctrineTypeMapping('smallint'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('decimal'));
$this->assertSame('decimal', $this->_platform->getDoctrineTypeMapping('decimal'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallmoney'));
$this->assertSame('integer', $this->_platform->getDoctrineTypeMapping('smallmoney'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('int'));
$this->assertSame('integer', $this->_platform->getDoctrineTypeMapping('int'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('tinyint'));
$this->assertSame('smallint', $this->_platform->getDoctrineTypeMapping('tinyint'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('money'));
$this->assertSame('integer', $this->_platform->getDoctrineTypeMapping('money'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('float'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('float'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('real'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('real'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('double'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('double'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('double precision'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('double precision'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('smalldatetime'));
$this->assertSame('datetime', $this->_platform->getDoctrineTypeMapping('smalldatetime'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('datetime'));
$this->assertSame('datetime', $this->_platform->getDoctrineTypeMapping('datetime'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('char'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('char'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('varchar'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('varchar'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('text'));
$this->assertSame('text', $this->_platform->getDoctrineTypeMapping('text'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('nchar'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('nchar'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('nvarchar'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('nvarchar'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('ntext'));
$this->assertSame('text', $this->_platform->getDoctrineTypeMapping('ntext'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('image'));
$this->assertSame('blob', $this->_platform->getDoctrineTypeMapping('image'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('uniqueidentifier'));
$this->assertSame('guid', $this->_platform->getDoctrineTypeMapping('uniqueidentifier'));
}
protected function getBinaryMaxLength()
{
return 8000;
}
public function testReturnsBinaryTypeDeclarationSQL()
{
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
$this->assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 8000)));
$this->assertSame('VARBINARY(MAX)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 8001)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
$this->assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 8000)));
$this->assertSame('VARBINARY(MAX)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 8001)));
}
/**
* @group DBAL-234
*/
protected function getAlterTableRenameIndexSQL()
{
return array(
"EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'",
);
}
/**
* @group DBAL-234
*/
protected function getQuotedAlterTableRenameIndexSQL()
{
return array(
"EXEC sp_RENAME N'[table].[create]', N'[select]', N'INDEX'",
"EXEC sp_RENAME N'[table].[foo]', N'[bar]', N'INDEX'",
);
}
}
...@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MySQL57Platform;
class MySQL57PlatformTest extends MySqlPlatformTest class MySQL57PlatformTest extends AbstractMySQLPlatformTestCase
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
......
...@@ -2,510 +2,12 @@ ...@@ -2,510 +2,12 @@
namespace Doctrine\Tests\DBAL\Platforms; namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Index;
class MySqlPlatformTest extends AbstractMySQLPlatformTestCase
class MySqlPlatformTest extends AbstractPlatformTestCase
{ {
public function createPlatform() public function createPlatform()
{ {
return new MysqlPlatform; return new MysqlPlatform;
} }
public function testModifyLimitQueryWitoutLimit()
{
$sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null , 10);
$this->assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql);
}
public function testGenerateMixedCaseTableCreate()
{
$table = new Table("Foo");
$table->addColumn("Bar", "integer");
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql));
}
public function getGenerateTableSql()
{
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB';
}
public function getGenerateTableWithMultiColumnUniqueIndexSql()
{
return array(
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
public function getGenerateAlterTableSql()
{
return array(
"ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"
);
}
public function testGeneratesSqlSnippets()
{
$this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
$this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Quote character is not correct');
$this->assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct');
}
public function testGeneratesTransactionsCommands()
{
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED),
''
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$this->assertEquals('SHOW DATABASES', $this->_platform->getListDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT AUTO_INCREMENT',
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
public function testGeneratesTypeDeclarationForStrings()
{
$this->assertEquals(
'CHAR(10)',
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'VARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'VARCHAR(255)',
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
}
public function testPrefersIdentityColumns()
{
$this->assertTrue($this->_platform->prefersIdentityColumns());
}
public function testSupportsIdentityColumns()
{
$this->assertTrue($this->_platform->supportsIdentityColumns());
}
public function testDoesSupportSavePoints()
{
$this->assertTrue($this->_platform->supportsSavepoints());
}
public function getGenerateIndexSql()
{
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
}
public function getGenerateUniqueIndexSql()
{
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
}
public function getGenerateForeignKeySql()
{
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
}
/**
* @group DBAL-126
*/
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);
}
public function testModifyLimitQuery()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
}
public function testModifyLimitQueryWithEmptyOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
$this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
}
/**
* @group DDC-118
*/
public function testGetDateTimeTypeDeclarationSql()
{
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false)));
$this->assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true)));
$this->assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array()));
}
public function getCreateTableColumnCommentsSQL()
{
return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
}
public function getAlterTableColumnCommentsSQL()
{
return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'");
}
public function getCreateTableColumnTypeCommentsSQL()
{
return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB");
}
/**
* @group DBAL-237
*/
public function testChangeIndexWithForeignKeys()
{
$index = new Index("idx", array("col"), false);
$unique = new Index("uniq", array("col"), true);
$diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index));
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql);
$diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique));
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql);
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
protected function getQuotedColumnInIndexSQL()
{
return array(
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
protected function getQuotedColumnInForeignKeySQL()
{
return array(
'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)',
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)',
'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)',
);
}
public function testCreateTableWithFulltextIndex()
{
$table = new Table('fulltext_table');
$table->addOption('engine', 'MyISAM');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'fulltext_text');
$index = $table->getIndex('fulltext_text');
$index->addFlag('fulltext');
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
}
public function testClobTypeDeclarationSQL()
{
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1)));
$this->assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255)));
$this->assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256)));
$this->assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535)));
$this->assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536)));
$this->assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215)));
$this->assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216)));
$this->assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array()));
}
public function testBlobTypeDeclarationSQL()
{
$this->assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1)));
$this->assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255)));
$this->assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256)));
$this->assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535)));
$this->assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536)));
$this->assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215)));
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216)));
$this->assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array()));
}
/**
* @group DBAL-400
*/
public function testAlterTableAddPrimaryKey()
{
$table = new Table('alter_table_add_pk');
$table->addColumn('id', 'integer');
$table->addColumn('foo', 'integer');
$table->addIndex(array('id'), 'idx_id');
$comparator = new Comparator();
$diffTable = clone $table;
$diffTable->dropIndex('idx_id');
$diffTable->setPrimaryKey(array('id'));
$this->assertEquals(
array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
/**
* @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->addColumn('bar', 'integer');
$table->setPrimaryKey(array('id', 'foo'));
$comparator = new Comparator();
$diffTable = clone $table;
$diffTable->dropPrimaryKey();
$this->assertEquals(
array(
'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL',
'ALTER TABLE drop_primary_key DROP PRIMARY KEY'
),
$this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))
);
}
/**
* @group DBAL-586
*/
public function testAddAutoIncrementPrimaryKey()
{
$keyTable = new Table("foo");
$keyTable->addColumn("id", "integer", array('autoincrement' => true));
$keyTable->addColumn("baz", "string");
$keyTable->setPrimaryKey(array("id"));
$oldTable = new Table("foo");
$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 id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)",
), $sql);
}
public function testNamedPrimaryKey()
{
$diff = new TableDiff('mytable');
$diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true);
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array(
"ALTER TABLE mytable DROP PRIMARY KEY",
"ALTER TABLE mytable ADD PRIMARY KEY (foo)",
), $sql);
}
public function testInitializesDoctrineTypeMappings()
{
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary'));
}
protected function getBinaryMaxLength()
{
return 65535;
}
public function testReturnsBinaryTypeDeclarationSQL()
{
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
$this->assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65535)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65536)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777215)));
$this->assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 16777216)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
$this->assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65536)));
$this->assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777215)));
$this->assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 16777216)));
}
public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines()
{
$table = new Table("foreign_table");
$table->addColumn('id', 'integer');
$table->addColumn('fk_id', 'integer');
$table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
$table->setPrimaryKey(array('id'));
$table->addOption('engine', 'MyISAM');
$this->assertSame(
array('CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'),
$this->_platform->getCreateTableSQL(
$table,
AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
)
);
$table = clone $table;
$table->addOption('engine', 'InnoDB');
$this->assertSame(
array(
'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)'
),
$this->_platform->getCreateTableSQL(
$table,
AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS
)
);
}
public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines()
{
$table = new Table("foreign_table");
$table->addColumn('id', 'integer');
$table->addColumn('fk_id', 'integer');
$table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id'));
$table->setPrimaryKey(array('id'));
$table->addOption('engine', 'MyISAM');
$addedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add'));
$changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change'));
$removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove'));
$tableDiff = new TableDiff('foreign_table');
$tableDiff->fromTable = $table;
$tableDiff->addedForeignKeys = $addedForeignKeys;
$tableDiff->changedForeignKeys = $changedForeignKeys;
$tableDiff->removedForeignKeys = $removedForeignKeys;
$this->assertEmpty($this->_platform->getAlterTableSQL($tableDiff));
$table->addOption('engine', 'InnoDB');
$tableDiff = new TableDiff('foreign_table');
$tableDiff->fromTable = $table;
$tableDiff->addedForeignKeys = $addedForeignKeys;
$tableDiff->changedForeignKeys = $changedForeignKeys;
$tableDiff->removedForeignKeys = $removedForeignKeys;
$this->assertSame(
array(
'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove',
'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change',
'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)',
'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)',
),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* @group DBAL-234
*/
protected function getAlterTableRenameIndexSQL()
{
return array(
'DROP INDEX idx_foo ON mytable',
'CREATE INDEX idx_bar ON mytable (id)',
);
}
/**
* @group DBAL-234
*/
protected function getQuotedAlterTableRenameIndexSQL()
{
return array(
'DROP INDEX `create` ON `table`',
'CREATE INDEX `select` ON `table` (id)',
'DROP INDEX `foo` ON `table`',
'CREATE INDEX `bar` ON `table` (id)',
);
}
} }
...@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\SQLServer2008Platform; use Doctrine\DBAL\Platforms\SQLServer2008Platform;
class SQLServer2008PlatformTest extends SQLServerPlatformTest class SQLServer2008PlatformTest extends AbstractSQLServerPlatformTestCase
{ {
public function createPlatform() public function createPlatform()
{ {
......
...@@ -5,7 +5,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -5,7 +5,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
class SQLServer2012PlatformTest extends SQLServerPlatformTest class SQLServer2012PlatformTest extends AbstractSQLServerPlatformTestCase
{ {
public function createPlatform() public function createPlatform()
{ {
......
...@@ -2,717 +2,13 @@ ...@@ -2,717 +2,13 @@
namespace Doctrine\Tests\DBAL\Platforms; namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\SQLServer2008Platform; use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\Type;
class SQLServerPlatformTest extends AbstractPlatformTestCase class SQLServerPlatformTest extends AbstractSQLServerPlatformTestCase
{ {
public function createPlatform() public function createPlatform()
{ {
return new SQLServer2008Platform; return new SQLServerPlatform;
} }
public function getGenerateTableSql()
{
return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test NVARCHAR(255), PRIMARY KEY (id))';
}
public function getGenerateTableWithMultiColumnUniqueIndexSql()
{
return array(
'CREATE TABLE test (foo NVARCHAR(255), bar NVARCHAR(255))',
'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL'
);
}
public function getGenerateAlterTableSql()
{
return array(
'ALTER TABLE mytable ADD quota INT',
'ALTER TABLE mytable DROP COLUMN foo',
'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) NOT NULL',
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_78240498 DEFAULT 'def' FOR baz",
'ALTER TABLE mytable ALTER COLUMN bloo BIT NOT NULL',
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_CECED971 DEFAULT '0' FOR bloo",
"sp_RENAME 'mytable', 'userlist'",
"DECLARE @sql NVARCHAR(MAX) = N''; " .
"SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " .
"+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''OBJECT'';' " .
"FROM sys.default_constraints dc " .
"JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " .
"WHERE tbl.name = 'userlist';" .
"EXEC sp_executesql @sql"
);
}
/**
* @expectedException Doctrine\DBAL\DBALException
*/
public function testDoesNotSupportRegexp()
{
$this->_platform->getRegexpExpression();
}
public function testGeneratesSqlSnippets()
{
$this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
$this->assertEquals('(column1 + column2 + column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
}
public function testGeneratesTransactionsCommands()
{
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
);
$this->assertEquals(
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
$this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
);
}
public function testGeneratesDDLSnippets()
{
$dropDatabaseExpectation = 'DROP DATABASE foobar';
$this->assertEquals('SELECT * FROM SYS.DATABASES', $this->_platform->getListDatabasesSQL());
$this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
$this->assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar'));
$this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
}
public function testGeneratesTypeDeclarationForIntegers()
{
$this->assertEquals(
'INT',
$this->_platform->getIntegerTypeDeclarationSQL(array())
);
$this->assertEquals(
'INT IDENTITY',
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
));
$this->assertEquals(
'INT IDENTITY',
$this->_platform->getIntegerTypeDeclarationSQL(
array('autoincrement' => true, 'primary' => true)
));
}
public function testGeneratesTypeDeclarationsForStrings()
{
$this->assertEquals(
'NCHAR(10)',
$this->_platform->getVarcharTypeDeclarationSQL(
array('length' => 10, 'fixed' => true)
));
$this->assertEquals(
'NVARCHAR(50)',
$this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
'Variable string declaration is not correct'
);
$this->assertEquals(
'NVARCHAR(255)',
$this->_platform->getVarcharTypeDeclarationSQL(array()),
'Long string declaration is not correct'
);
$this->assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL(array()));
$this->assertSame(
'VARCHAR(MAX)',
$this->_platform->getClobTypeDeclarationSQL(array('length' => 5, 'fixed' => true))
);
}
public function testPrefersIdentityColumns()
{
$this->assertTrue($this->_platform->prefersIdentityColumns());
}
public function testSupportsIdentityColumns()
{
$this->assertTrue($this->_platform->supportsIdentityColumns());
}
public function testSupportsSchemas()
{
$this->assertTrue($this->_platform->supportsSchemas());
}
public function testDoesNotSupportSavePoints()
{
$this->assertTrue($this->_platform->supportsSavepoints());
}
public function getGenerateIndexSql()
{
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
}
public function getGenerateUniqueIndexSql()
{
return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL';
}
public function getGenerateForeignKeySql()
{
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
}
public function testModifyLimitQuery()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithEmptyOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
}
public function testModifyLimitQueryWithAscOrderBy()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username ASC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithDescOrderBy()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithMultipleOrderBy()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC, usereamil ASC', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC, usereamil ASC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithSubSelect()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM (SELECT u.id as uid, u.name as uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithSubSelectAndOrder()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC) dctrn_result', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY u.name DESC) AS doctrine_rownum FROM (SELECT u.id as uid, u.name as uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result', 10);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY name DESC) AS doctrine_rownum FROM (SELECT u.id, u.name) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
public function testModifyLimitQueryWithSubSelectAndMultipleOrder()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY u.name DESC, id ASC) AS doctrine_rownum FROM (SELECT u.id as uid, u.name as uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY u.name DESC, id ASC) AS doctrine_rownum FROM (SELECT u.id uid, u.name uname) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result', 10, 5);
$this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY name DESC, id ASC) AS doctrine_rownum FROM (SELECT u.id, u.name) dctrn_result) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
}
public function testModifyLimitQueryWithFromColumnNames()
{
$sql = $this->_platform->modifyLimitQuery('SELECT a.fromFoo, fromBar FROM foo', 10);
$this->assertEquals('SELECT * FROM (SELECT a.fromFoo, fromBar, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM foo) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 1 AND 10', $sql);
}
/**
* @group DDC-2470
*/
public function testModifyLimitQueryWithOrderByClause()
{
$sql = 'SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2 FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ? ORDER BY m0_.FECHAINICIO DESC';
$expected = 'SELECT * FROM (SELECT m0_.NOMBRE AS NOMBRE0, m0_.FECHAINICIO AS FECHAINICIO1, m0_.FECHAFIN AS FECHAFIN2, ROW_NUMBER() OVER (ORDER BY m0_.FECHAINICIO DESC) AS doctrine_rownum FROM MEDICION m0_ WITH (NOLOCK) INNER JOIN ESTUDIO e1_ ON m0_.ESTUDIO_ID = e1_.ID INNER JOIN CLIENTE c2_ ON e1_.CLIENTE_ID = c2_.ID INNER JOIN USUARIO u3_ ON c2_.ID = u3_.CLIENTE_ID WHERE u3_.ID = ?) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15';
$actual = $this->_platform->modifyLimitQuery($sql, 10, 5);
$this->assertEquals($expected, $actual);
}
/**
* @group DDC-1360
*/
public function testQuoteIdentifier()
{
$this->assertEquals('[fo][o]', $this->_platform->quoteIdentifier('fo]o'));
$this->assertEquals('[test]', $this->_platform->quoteIdentifier('test'));
$this->assertEquals('[test].[test]', $this->_platform->quoteIdentifier('test.test'));
}
/**
* @group DDC-1360
*/
public function testQuoteSingleIdentifier()
{
$this->assertEquals('[fo][o]', $this->_platform->quoteSingleIdentifier('fo]o'));
$this->assertEquals('[test]', $this->_platform->quoteSingleIdentifier('test'));
$this->assertEquals('[test.test]', $this->_platform->quoteSingleIdentifier('test.test'));
}
/**
* @group DBAL-220
*/
public function testCreateClusteredIndex()
{
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'));
$idx->addFlag('clustered');
$this->assertEquals('CREATE CLUSTERED INDEX idx ON tbl (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl'));
}
/**
* @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));
}
/**
* @group DBAL-220
*/
public function testCreateNonClusteredPrimaryKey()
{
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true);
$idx->addFlag('nonclustered');
$this->assertEquals('ALTER TABLE tbl ADD PRIMARY KEY NONCLUSTERED (id)', $this->_platform->getCreatePrimaryKeySQL($idx, 'tbl'));
}
public function testAlterAddPrimaryKey()
{
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true);
$this->assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl'));
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))',
);
}
protected function getQuotedColumnInIndexSQL()
{
return array(
'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL)',
'CREATE INDEX IDX_22660D028FD6E0FB ON [quoted] ([create])',
);
}
protected function getQuotedColumnInForeignKeySQL()
{
return array(
'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, foo NVARCHAR(255) NOT NULL, [bar] NVARCHAR(255) NOT NULL)',
'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ([create], foo, [bar]) REFERENCES [foreign] ([create], bar, [foo-bar])',
'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ([create], foo, [bar]) REFERENCES foo ([create], bar, [foo-bar])',
'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ([create], foo, [bar]) REFERENCES [foo-bar] ([create], bar, [foo-bar])',
);
}
public function testGetCreateSchemaSQL()
{
$schemaName = 'schema';
$sql = $this->_platform->getCreateSchemaSQL($schemaName);
$this->assertEquals('CREATE SCHEMA ' . $schemaName, $sql);
}
public function testSchemaNeedsCreation()
{
$schemaNames = array(
'dbo' => false,
'schema' => true,
);
foreach ($schemaNames as $name => $expected) {
$actual = $this->_platform->schemaNeedsCreation($name);
$this->assertEquals($expected, $actual);
}
}
/**
* @group DBAL-543
*/
public function getCreateTableColumnCommentsSQL()
{
return array(
"CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))",
"EXEC sp_addextendedproperty N'MS_Description', N'This is a comment', N'SCHEMA', dbo, N'TABLE', test, N'COLUMN', id",
);
}
/**
* @group DBAL-543
*/
public function getAlterTableColumnCommentsSQL()
{
return array(
"ALTER TABLE mytable ADD quota INT NOT NULL",
"EXEC sp_addextendedproperty N'MS_Description', N'A comment', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', quota",
// todo
//"EXEC sp_addextendedproperty N'MS_Description', N'B comment', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', baz",
);
}
/**
* @group DBAL-543
*/
public function getCreateTableColumnTypeCommentsSQL()
{
return array(
"CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', test, N'COLUMN', data",
);
}
/**
* @group DBAL-543
*/
public function testGeneratesCreateTableSQLWithColumnComments()
{
$table = new Table('mytable');
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('comment_null', 'integer', array('comment' => null));
$table->addColumn('comment_false', 'integer', array('comment' => false));
$table->addColumn('comment_empty_string', 'integer', array('comment' => ''));
$table->addColumn('comment_integer_0', 'integer', array('comment' => 0));
$table->addColumn('comment_float_0', 'integer', array('comment' => 0.0));
$table->addColumn('comment_string_0', 'integer', array('comment' => '0'));
$table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!'));
$table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!'));
$table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!'));
$table->addColumn('commented_type', 'object');
$table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.'));
$table->setPrimaryKey(array('id'));
$this->assertEquals(
array(
"CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_integer_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_float_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_string_0",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz you!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for explicitely quoted columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [comment_quoted]",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine 0wnz comments for reserved keyword columns!', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [create]",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine array type.(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type_with_comment",
),
$this->_platform->getCreateTableSQL($table)
);
}
/**
* @group DBAL-543
*/
public function testGeneratesAlterTableSQLWithColumnComments()
{
$table = new Table('mytable');
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('comment_null', 'integer', array('comment' => null));
$table->addColumn('comment_false', 'integer', array('comment' => false));
$table->addColumn('comment_empty_string', 'integer', array('comment' => ''));
$table->addColumn('comment_integer_0', 'integer', array('comment' => 0));
$table->addColumn('comment_float_0', 'integer', array('comment' => 0.0));
$table->addColumn('comment_string_0', 'integer', array('comment' => '0'));
$table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!'));
$table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitely quoted columns!'));
$table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!'));
$table->addColumn('commented_type', 'object');
$table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.'));
$table->setPrimaryKey(array('id'));
$tableDiff = new TableDiff('mytable');
$tableDiff->fromTable = $table;
$tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer'));
$tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null));
$tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false));
$tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => ''));
$tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0));
$tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0));
$tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0'));
$tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine'));
$tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez'));
$tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666'));
$tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object'));
$tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666'));
$tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!'));
// Add comment to non-commented column.
$tableDiff->changedColumns['id'] = new ColumnDiff(
'id',
new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')),
array('comment'),
new Column('id', Type::getType('integer'), array('autoincrement' => true))
);
// Remove comment from null-commented column.
$tableDiff->changedColumns['comment_null'] = new ColumnDiff(
'comment_null',
new Column('comment_null', Type::getType('string')),
array('type'),
new Column('comment_null', Type::getType('integer'), array('comment' => null))
);
// Add comment to false-commented column.
$tableDiff->changedColumns['comment_false'] = new ColumnDiff(
'comment_false',
new Column('comment_false', Type::getType('integer'), array('comment' => 'false')),
array('comment'),
new Column('comment_false', Type::getType('integer'), array('comment' => false))
);
// Change type to custom type from empty string commented column.
$tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff(
'comment_empty_string',
new Column('comment_empty_string', Type::getType('object')),
array('type'),
new Column('comment_empty_string', Type::getType('integer'), array('comment' => ''))
);
// Change comment to false-comment from zero-string commented column.
$tableDiff->changedColumns['comment_string_0'] = new ColumnDiff(
'comment_string_0',
new Column('comment_string_0', Type::getType('integer'), array('comment' => false)),
array('comment'),
new Column('comment_string_0', Type::getType('integer'), array('comment' => '0'))
);
// Remove comment from regular commented column.
$tableDiff->changedColumns['comment'] = new ColumnDiff(
'comment',
new Column('comment', Type::getType('integer')),
array('comment'),
new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!'))
);
// Change comment and change type to custom type from regular commented column.
$tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff(
'`comment_quoted`',
new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')),
array('comment', 'type'),
new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!'))
);
// Remove comment and change type to custom type from regular commented column.
$tableDiff->changedColumns['create'] = new ColumnDiff(
'create',
new Column('create', Type::getType('object')),
array('comment', 'type'),
new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!'))
);
// Add comment and change custom type to regular type from non-commented column.
$tableDiff->changedColumns['commented_type'] = new ColumnDiff(
'commented_type',
new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')),
array('comment', 'type'),
new Column('commented_type', Type::getType('object'))
);
// Remove comment from commented custom type column.
$tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff(
'commented_type_with_comment',
new Column('commented_type_with_comment', Type::getType('array')),
array('comment'),
new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.'))
);
$tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0));
$this->assertEquals(
array(
// Renamed columns.
"sp_RENAME 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'",
// Added columns.
"ALTER TABLE mytable ADD added_comment_none INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_null INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_false INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL",
"ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL",
"ALTER TABLE mytable ADD added_comment INT NOT NULL",
"ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL",
"ALTER TABLE mytable ADD [select] INT NOT NULL",
"ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable DROP COLUMN comment_integer_0",
"ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL",
"ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL",
// Renamed columns.
"ALTER TABLE mytable ALTER COLUMN comment_double_0 NUMERIC(10, 0) NOT NULL",
// Added columns.
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment_integer_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment_float_0",
"EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment_string_0",
"EXEC sp_addextendedproperty N'MS_Description', N'Doctrine', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_comment",
"EXEC sp_addextendedproperty N'MS_Description', N'rulez', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [added_comment_quoted]",
"EXEC sp_addextendedproperty N'MS_Description', N'666', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [select]",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_commented_type",
"EXEC sp_addextendedproperty N'MS_Description', N'666(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', added_commented_type_with_comment",
// Changed columns.
"EXEC sp_addextendedproperty N'MS_Description', N'primary', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', id",
"EXEC sp_addextendedproperty N'MS_Description', N'false', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_false",
"EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_empty_string",
"EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment_string_0",
"EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', comment",
"EXEC sp_updateextendedproperty N'MS_Description', N'Doctrine array.(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [comment_quoted]",
"EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', [create]",
"EXEC sp_updateextendedproperty N'MS_Description', N'foo', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type",
"EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', commented_type_with_comment",
),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* @group DBAL-122
*/
public function testInitializesDoctrineTypeMappings()
{
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('bigint'));
$this->assertSame('bigint', $this->_platform->getDoctrineTypeMapping('bigint'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('numeric'));
$this->assertSame('decimal', $this->_platform->getDoctrineTypeMapping('numeric'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('bit'));
$this->assertSame('boolean', $this->_platform->getDoctrineTypeMapping('bit'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallint'));
$this->assertSame('smallint', $this->_platform->getDoctrineTypeMapping('smallint'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('decimal'));
$this->assertSame('decimal', $this->_platform->getDoctrineTypeMapping('decimal'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallmoney'));
$this->assertSame('integer', $this->_platform->getDoctrineTypeMapping('smallmoney'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('int'));
$this->assertSame('integer', $this->_platform->getDoctrineTypeMapping('int'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('tinyint'));
$this->assertSame('smallint', $this->_platform->getDoctrineTypeMapping('tinyint'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('money'));
$this->assertSame('integer', $this->_platform->getDoctrineTypeMapping('money'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('float'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('float'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('real'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('real'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('double'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('double'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('double precision'));
$this->assertSame('float', $this->_platform->getDoctrineTypeMapping('double precision'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('smalldatetime'));
$this->assertSame('datetime', $this->_platform->getDoctrineTypeMapping('smalldatetime'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('datetime'));
$this->assertSame('datetime', $this->_platform->getDoctrineTypeMapping('datetime'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('char'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('char'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('varchar'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('varchar'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('text'));
$this->assertSame('text', $this->_platform->getDoctrineTypeMapping('text'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('nchar'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('nchar'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('nvarchar'));
$this->assertSame('string', $this->_platform->getDoctrineTypeMapping('nvarchar'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('ntext'));
$this->assertSame('text', $this->_platform->getDoctrineTypeMapping('ntext'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary'));
$this->assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('image'));
$this->assertSame('blob', $this->_platform->getDoctrineTypeMapping('image'));
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('uniqueidentifier'));
$this->assertSame('guid', $this->_platform->getDoctrineTypeMapping('uniqueidentifier'));
}
protected function getBinaryMaxLength()
{
return 8000;
}
public function testReturnsBinaryTypeDeclarationSQL()
{
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array()));
$this->assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
$this->assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 8000)));
$this->assertSame('VARBINARY(MAX)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 8001)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
$this->assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
$this->assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 8000)));
$this->assertSame('VARBINARY(MAX)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 8001)));
}
/**
* @group DBAL-234
*/
protected function getAlterTableRenameIndexSQL()
{
return array(
"EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'",
);
}
/**
* @group DBAL-234
*/
protected function getQuotedAlterTableRenameIndexSQL()
{
return array(
"EXEC sp_RENAME N'[table].[create]', N'[select]', N'INDEX'",
"EXEC sp_RENAME N'[table].[foo]', N'[bar]', N'INDEX'",
);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment