3 namespace Doctrine\Tests\DBAL\Platforms;
5 use Doctrine\DBAL\Platforms\SqlitePlatform;
6 use Doctrine\DBAL\Types\Type;
8 require_once __DIR__ . '/../../TestInit.php';
10 class SqlitePlatformTest extends AbstractPlatformTestCase
12 public function createPlatform()
14 return new SqlitePlatform;
17 public function getGenerateTableSql()
19 return 'CREATE TABLE test (id INTEGER NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
22 public function getGenerateTableWithMultiColumnUniqueIndexSql()
25 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
26 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
30 public function testGeneratesSqlSnippets()
32 $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
33 $this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
34 $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct');
37 public function testGeneratesTransactionCommands()
40 'PRAGMA read_uncommitted = 0',
41 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
44 'PRAGMA read_uncommitted = 1',
45 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
48 'PRAGMA read_uncommitted = 1',
49 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
52 'PRAGMA read_uncommitted = 1',
53 $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
57 public function testPrefersIdentityColumns()
59 $this->assertTrue($this->_platform->prefersIdentityColumns());
62 public function testGeneratesTypeDeclarationForIntegers()
66 $this->_platform->getIntegerTypeDeclarationSQL(array())
70 $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true))
74 $this->_platform->getIntegerTypeDeclarationSQL(
75 array('autoincrement' => true, 'primary' => true))
79 public function testGeneratesTypeDeclarationForStrings()
83 $this->_platform->getVarcharTypeDeclarationSQL(
84 array('length' => 10, 'fixed' => true))
88 $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
89 'Variable string declaration is not correct'
93 $this->_platform->getVarcharTypeDeclarationSQL(array()),
94 'Long string declaration is not correct'
98 public function getGenerateIndexSql()
100 return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
103 public function getGenerateUniqueIndexSql()
105 return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
108 public function getGenerateForeignKeySql()
110 $this->markTestSkipped('SQLite does not support ForeignKeys.');
113 public function testModifyLimitQuery()
115 $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
116 $this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
119 public function testModifyLimitQueryWithEmptyOffset()
121 $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
122 $this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
125 public function getGenerateAlterTableSql()
127 $this->markTestSkipped('SQlite does not support ALTER Table.');
130 public function testGetAlterTableSqlDispatchEvent()
132 $this->markTestSkipped('SQlite does not support ALTER Table.');
138 public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey()
140 $table = new \Doctrine\DBAL\Schema\Table('test');
141 $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true));
142 $table->setPrimaryKey(array('"like"'));
144 $createTableSQL = $this->_platform->getCreateTableSQL($table);
146 'CREATE TABLE test ("like" INTEGER NOT NULL, PRIMARY KEY("like"))',
151 'ALTER TABLE test ADD PRIMARY KEY ("like")',
152 $this->_platform->getCreatePrimaryKeySQL($table->getIndex('primary'), 'test')