2009-02-18 02:27:11 +03:00
< ? php
namespace Doctrine\Tests\DBAL\Platforms ;
2009-02-18 13:26:12 +03:00
use Doctrine\DBAL\Platforms\SqlitePlatform ;
2009-05-28 15:13:12 +04:00
use Doctrine\DBAL\Types\Type ;
2009-02-18 13:26:12 +03:00
2009-02-18 02:27:11 +03:00
require_once __DIR__ . '/../../TestInit.php' ;
2009-12-02 21:52:21 +03:00
class SqlitePlatformTest extends AbstractPlatformTestCase
2009-02-18 02:27:11 +03:00
{
2009-12-02 21:52:21 +03:00
public function createPlatform ()
2009-02-18 02:27:11 +03:00
{
2009-12-02 21:52:21 +03:00
return new SqlitePlatform ;
2009-02-18 02:27:11 +03:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateTableSql ()
2009-02-18 02:27:11 +03:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL)' ;
2009-02-18 02:27:11 +03:00
}
2009-07-07 16:00:22 +04:00
public function testGeneratesSqlSnippets ()
2009-02-18 02:27:11 +03:00
{
2009-07-07 16:00:22 +04:00
$this -> assertEquals ( 'RLIKE' , $this -> _platform -> getRegexpExpression (), 'Regular expression operator is not correct' );
$this -> assertEquals ( 'SUBSTR(column, 5, LENGTH(column))' , $this -> _platform -> getSubstringExpression ( 'column' , 5 ), 'Substring expression without length is not correct' );
$this -> assertEquals ( 'SUBSTR(column, 0, 5)' , $this -> _platform -> getSubstringExpression ( 'column' , 0 , 5 ), 'Substring expression with length is not correct' );
2009-02-18 02:27:11 +03:00
}
2009-07-07 16:00:22 +04:00
public function testGeneratesTransactionCommands ()
2009-02-18 02:27:11 +03:00
{
2009-05-03 22:07:57 +04:00
$this -> assertEquals ( 'PRAGMA read_uncommitted = 0' , $this -> _platform -> getSetTransactionIsolationSql ( \Doctrine\DBAL\Connection :: TRANSACTION_READ_UNCOMMITTED ));
$this -> assertEquals ( 'PRAGMA read_uncommitted = 1' , $this -> _platform -> getSetTransactionIsolationSql ( \Doctrine\DBAL\Connection :: TRANSACTION_READ_COMMITTED ));
$this -> assertEquals ( 'PRAGMA read_uncommitted = 1' , $this -> _platform -> getSetTransactionIsolationSql ( \Doctrine\DBAL\Connection :: TRANSACTION_REPEATABLE_READ ));
$this -> assertEquals ( 'PRAGMA read_uncommitted = 1' , $this -> _platform -> getSetTransactionIsolationSql ( \Doctrine\DBAL\Connection :: TRANSACTION_SERIALIZABLE ));
}
2009-07-07 16:00:22 +04:00
public function testPrefersIdentityColumns ()
2009-05-03 22:07:57 +04:00
{
$this -> assertTrue ( $this -> _platform -> prefersIdentityColumns ());
}
2009-07-07 16:00:22 +04:00
public function testGeneratesTypeDeclarationForIntegers ()
2009-05-03 22:07:57 +04:00
{
$this -> assertEquals (
'INTEGER' ,
$this -> _platform -> getIntegerTypeDeclarationSql ( array ())
);
$this -> assertEquals (
'INTEGER AUTOINCREMENT' ,
2009-07-07 16:00:22 +04:00
$this -> _platform -> getIntegerTypeDeclarationSql ( array ( 'autoincrement' => true ))
);
2009-05-03 22:07:57 +04:00
$this -> assertEquals (
'INTEGER PRIMARY KEY AUTOINCREMENT' ,
$this -> _platform -> getIntegerTypeDeclarationSql (
2009-07-07 16:00:22 +04:00
array ( 'autoincrement' => true , 'primary' => true ))
);
}
public function testGeneratesTypeDeclarationForStrings ()
{
2009-05-03 22:07:57 +04:00
$this -> assertEquals (
'CHAR(10)' ,
$this -> _platform -> getVarcharTypeDeclarationSql (
2009-07-07 16:00:22 +04:00
array ( 'length' => 10 , 'fixed' => true ))
);
2009-05-03 22:07:57 +04:00
$this -> assertEquals (
'VARCHAR(50)' ,
2009-07-07 16:00:22 +04:00
$this -> _platform -> getVarcharTypeDeclarationSql ( array ( 'length' => 50 )),
'Variable string declaration is not correct'
2009-05-03 22:07:57 +04:00
);
$this -> assertEquals (
'TEXT' ,
2009-07-07 16:00:22 +04:00
$this -> _platform -> getVarcharTypeDeclarationSql ( array ()),
'Long string declaration is not correct'
2009-05-03 22:07:57 +04:00
);
2009-02-18 02:27:11 +03:00
}
2009-07-07 16:00:22 +04:00
2009-12-02 21:52:21 +03:00
public function getGenerateIndexSql ()
{
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)' ;
}
public function getGenerateUniqueIndexSql ()
2009-07-07 16:00:22 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)' ;
2009-07-07 16:00:22 +04:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateForeignKeySql ()
2009-07-07 16:00:22 +04:00
{
2009-12-02 21:52:21 +03:00
$this -> markTestSkipped ( 'SQLite does not support ForeignKeys.' );
2009-07-07 16:00:22 +04:00
}
2009-07-14 02:59:36 +04:00
public function testModifyLimitQuery ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user' , 10 , 0 );
2009-10-12 23:10:41 +04:00
$this -> assertEquals ( 'SELECT * FROM user LIMIT 10 OFFSET 0' , $sql );
2009-07-14 02:59:36 +04:00
}
public function testModifyLimitQueryWithEmptyOffset ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user' , 10 );
$this -> assertEquals ( 'SELECT * FROM user LIMIT 10' , $sql );
}
2009-12-06 02:06:29 +03:00
public function getGenerateAlterTableSql ()
{
$this -> markTestSkipped ( 'SQlite does not support ALTER Table.' );
}
2009-07-14 02:59:36 +04:00
}