3 namespace Doctrine\Tests\DBAL\Platforms;
5 use Doctrine\DBAL\Platforms\OraclePlatform;
6 use Doctrine\DBAL\Types\Type;
8 require_once __DIR__ . '/../../TestInit.php';
10 class OraclePlatformTest extends AbstractPlatformTestCase
12 static public function dataValidIdentifiers()
19 array('Foo#bar_baz$'),
28 * @dataProvider dataValidIdentifiers
30 public function testValidIdentifiers($identifier)
32 $platform = $this->createPlatform();
33 $platform->assertValidIdentifier($identifier);
36 static public function dataInvalidIdentifiers()
48 * @dataProvider dataInvalidIdentifiers
50 public function testInvalidIdentifiers($identifier)
52 $this->setExpectedException('Doctrine\DBAL\DBALException');
53 $platform = $this->createPlatform();
54 $platform->assertValidIdentifier($identifier);
57 public function createPlatform()
59 return new OraclePlatform;
62 public function getGenerateTableSql()
64 return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))';
67 public function getGenerateTableWithMultiColumnUniqueIndexSql()
70 'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL, bar VARCHAR2(255) DEFAULT NULL)',
71 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
75 public function getGenerateAlterTableSql()
78 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)',
79 "ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo NUMBER(1) DEFAULT '0' NOT NULL)",
80 "ALTER TABLE mytable DROP (foo)",
81 "ALTER TABLE mytable RENAME TO userlist",
86 * @expectedException Doctrine\DBAL\DBALException
88 public function testRLike()
90 $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
93 public function testGeneratesSqlSnippets()
95 $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
96 $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
99 public function testGeneratesTransactionsCommands()
102 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
103 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
106 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED',
107 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
110 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
111 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
114 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE',
115 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
120 * @expectedException Doctrine\DBAL\DBALException
122 public function testShowDatabasesThrowsException()
124 $this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSQL());
128 * @expectedException Doctrine\DBAL\DBALException
130 public function testCreateDatabaseThrowsException()
132 $this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
135 public function testDropDatabaseThrowsException()
137 $this->assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSQL('foobar'));
140 public function testDropTable()
142 $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
145 public function testGeneratesTypeDeclarationForIntegers()
149 $this->_platform->getIntegerTypeDeclarationSQL(array())
153 $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
157 $this->_platform->getIntegerTypeDeclarationSQL(
158 array('autoincrement' => true, 'primary' => true)
162 public function testGeneratesTypeDeclarationsForStrings()
166 $this->_platform->getVarcharTypeDeclarationSQL(
167 array('length' => 10, 'fixed' => true)
171 $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
172 'Variable string declaration is not correct'
176 $this->_platform->getVarcharTypeDeclarationSQL(array()),
177 'Long string declaration is not correct'
181 public function testPrefersIdentityColumns()
183 $this->assertFalse($this->_platform->prefersIdentityColumns());
186 public function testSupportsIdentityColumns()
188 $this->assertFalse($this->_platform->supportsIdentityColumns());
191 public function testSupportsSavePoints()
193 $this->assertTrue($this->_platform->supportsSavepoints());
196 public function getGenerateIndexSql()
198 return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
201 public function getGenerateUniqueIndexSql()
203 return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
206 public function getGenerateForeignKeySql()
208 return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
211 public function testModifyLimitQuery()
213 $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
214 $this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
217 public function testModifyLimitQueryWithEmptyOffset()
219 $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
220 $this->assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql);
223 public function testModifyLimitQueryWithAscOrderBy()
225 $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10);
226 $this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10', $sql);
229 public function testModifyLimitQueryWithDescOrderBy()
231 $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10);
232 $this->assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql);
235 public function getCreateTableColumnCommentsSQL()
238 "CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))",
239 "COMMENT ON COLUMN test.id IS 'This is a comment'",
243 public function getCreateTableColumnTypeCommentsSQL()
246 "CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))",
247 "COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
251 public function getAlterTableColumnCommentsSQL()
254 "ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)",
255 "ALTER TABLE mytable MODIFY (baz VARCHAR2(255) NOT NULL)",
256 "COMMENT ON COLUMN mytable.quota IS 'A comment'",
257 "COMMENT ON COLUMN mytable.baz IS 'B comment'",
261 public function getBitAndComparisonExpressionSql($value1, $value2)
263 return 'BITAND('.$value1 . ', ' . $value2 . ')';
266 public function getBitOrComparisonExpressionSql($value1, $value2)
268 return '(' . $value1 . '-' .
269 $this->getBitAndComparisonExpressionSql($value1, $value2)
270 . '+' . $value2 . ')';