2009-07-14 02:59:36 +04:00
< ? php
namespace Doctrine\Tests\DBAL\Platforms ;
use Doctrine\DBAL\Platforms\OraclePlatform ;
use Doctrine\DBAL\Types\Type ;
require_once __DIR__ . '/../../TestInit.php' ;
2009-12-02 21:52:21 +03:00
class OraclePlatformTest extends AbstractPlatformTestCase
2009-07-14 02:59:36 +04:00
{
2009-12-02 21:52:21 +03:00
public function createPlatform ()
2009-07-14 02:59:36 +04:00
{
2009-12-02 21:52:21 +03:00
return new OraclePlatform ;
2009-07-14 02:59:36 +04:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateTableSql ()
2009-07-14 02:59:36 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))' ;
2009-07-14 02:59:36 +04:00
}
2009-12-11 02:55:47 +03:00
public function getGenerateTableWithMultiColumnUniqueIndexSql ()
{
return array (
'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL, bar VARCHAR2(255) DEFAULT NULL)' ,
'CREATE UNIQUE INDEX test_foo_bar_uniq ON test (foo, bar)' ,
);
}
2009-12-06 02:06:29 +03:00
public function getGenerateAlterTableSql ()
2009-07-14 02:59:36 +04:00
{
2009-12-06 02:06:29 +03:00
return array (
2009-07-14 02:59:36 +04:00
'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)' ,
2009-12-06 15:13:15 +03:00
" ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL) " ,
" ALTER TABLE mytable DROP COLUMN foo " ,
" ALTER TABLE mytable RENAME TO userlist " ,
2009-07-14 02:59:36 +04:00
);
}
/**
2009-11-03 21:30:21 +03:00
* @ expectedException Doctrine\DBAL\DBALException
2009-07-14 02:59:36 +04:00
*/
public function testRLike ()
{
$this -> assertEquals ( 'RLIKE' , $this -> _platform -> getRegexpExpression (), 'Regular expression operator is not correct' );
}
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' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getSetTransactionIsolationSQL ( \Doctrine\DBAL\Connection :: TRANSACTION_READ_UNCOMMITTED )
2009-07-14 02:59:36 +04:00
);
$this -> assertEquals (
'SET TRANSACTION ISOLATION LEVEL READ COMMITTED' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getSetTransactionIsolationSQL ( \Doctrine\DBAL\Connection :: TRANSACTION_READ_COMMITTED )
2009-07-14 02:59:36 +04:00
);
$this -> assertEquals (
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getSetTransactionIsolationSQL ( \Doctrine\DBAL\Connection :: TRANSACTION_REPEATABLE_READ )
2009-07-14 02:59:36 +04:00
);
$this -> assertEquals (
'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getSetTransactionIsolationSQL ( \Doctrine\DBAL\Connection :: TRANSACTION_SERIALIZABLE )
2009-07-14 02:59:36 +04:00
);
}
/**
2009-11-03 21:30:21 +03:00
* @ expectedException Doctrine\DBAL\DBALException
2009-07-14 02:59:36 +04:00
*/
public function testShowDatabasesThrowsException ()
{
2010-03-05 19:35:00 +03:00
$this -> assertEquals ( 'SHOW DATABASES' , $this -> _platform -> getShowDatabasesSQL ());
2009-07-14 02:59:36 +04:00
}
/**
2009-11-03 21:30:21 +03:00
* @ expectedException Doctrine\DBAL\DBALException
2009-07-14 02:59:36 +04:00
*/
public function testCreateDatabaseThrowsException ()
{
2010-03-05 19:35:00 +03:00
$this -> assertEquals ( 'CREATE DATABASE foobar' , $this -> _platform -> getCreateDatabaseSQL ( 'foobar' ));
2009-07-14 02:59:36 +04:00
}
public function testDropDatabaseThrowsException ()
{
2010-03-05 19:35:00 +03:00
$this -> assertEquals ( 'DROP USER foobar CASCADE' , $this -> _platform -> getDropDatabaseSQL ( 'foobar' ));
2009-07-14 02:59:36 +04:00
}
public function testDropTable ()
{
2010-03-05 19:35:00 +03:00
$this -> assertEquals ( 'DROP TABLE foobar' , $this -> _platform -> getDropTableSQL ( 'foobar' ));
2009-07-14 02:59:36 +04:00
}
public function testGeneratesTypeDeclarationForIntegers ()
{
$this -> assertEquals (
'NUMBER(10)' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getIntegerTypeDeclarationSQL ( array ())
2009-07-14 02:59:36 +04:00
);
$this -> assertEquals (
'NUMBER(10)' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getIntegerTypeDeclarationSQL ( array ( 'autoincrement' => true )
2009-07-14 02:59:36 +04:00
));
$this -> assertEquals (
'NUMBER(10)' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getIntegerTypeDeclarationSQL (
2009-07-14 02:59:36 +04:00
array ( 'autoincrement' => true , 'primary' => true )
));
}
public function testGeneratesTypeDeclarationsForStrings ()
{
$this -> assertEquals (
'CHAR(10)' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getVarcharTypeDeclarationSQL (
2009-07-14 02:59:36 +04:00
array ( 'length' => 10 , 'fixed' => true )
));
$this -> assertEquals (
'VARCHAR2(50)' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getVarcharTypeDeclarationSQL ( array ( 'length' => 50 )),
2009-07-14 02:59:36 +04:00
'Variable string declaration is not correct'
);
$this -> assertEquals (
'VARCHAR2(4000)' ,
2010-03-05 19:35:00 +03:00
$this -> _platform -> getVarcharTypeDeclarationSQL ( array ()),
2009-07-14 02:59:36 +04:00
'Long string declaration is not correct'
);
}
public function testPrefersIdentityColumns ()
{
$this -> assertFalse ( $this -> _platform -> prefersIdentityColumns ());
}
public function testSupportsIdentityColumns ()
{
$this -> assertFalse ( $this -> _platform -> supportsIdentityColumns ());
}
public function testSupportsSavePoints ()
{
$this -> assertTrue ( $this -> _platform -> supportsSavepoints ());
}
2009-12-03 01:28:38 +03:00
2009-12-02 21:52:21 +03:00
public function getGenerateIndexSql ()
2009-07-14 02:59:36 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)' ;
2009-07-14 02:59:36 +04:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateUniqueIndexSql ()
2009-07-14 02:59:36 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)' ;
2009-07-14 02:59:36 +04:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateForeignKeySql ()
2009-07-14 02:59:36 +04:00
{
2009-12-02 21:52:21 +03:00
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)' ;
2009-07-14 02:59:36 +04:00
}
public function testModifyLimitQuery ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user' , 10 , 0 );
$this -> assertEquals ( 'SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10' , $sql );
}
public function testModifyLimitQueryWithEmptyOffset ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user' , 10 );
$this -> assertEquals ( 'SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10' , $sql );
}
public function testModifyLimitQueryWithAscOrderBy ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user ORDER BY username ASC' , 10 );
$this -> assertEquals ( 'SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10' , $sql );
}
public function testModifyLimitQueryWithDescOrderBy ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user ORDER BY username DESC' , 10 );
$this -> assertEquals ( 'SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10' , $sql );
}
}