Skip to content

Commit

Permalink
Merge pull request #158 from FabioBatSilva/DDC-1845
Browse files Browse the repository at this point in the history
[SQLITE] Remove primary key auto quote
  • Loading branch information
guilhermeblanco committed Jun 25, 2012
2 parents 2cac730 + 93bacd3 commit baf30ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ protected function _getCreateTableSQL($name, array $columns, array $options = ar

if (isset($options['primary']) && ! empty($options['primary'])) {
$keyColumns = array_unique(array_values($options['primary']));
$keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns);
$queryFields.= ', PRIMARY KEY('.implode(', ', $keyColumns).')';
}

Expand Down
23 changes: 22 additions & 1 deletion tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function createPlatform()

public function getGenerateTableSql()
{
return 'CREATE TABLE test (id INTEGER NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY("id"))';
return 'CREATE TABLE test (id INTEGER NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
}

public function getGenerateTableWithMultiColumnUniqueIndexSql()
Expand Down Expand Up @@ -131,4 +131,25 @@ public function testGetAlterTableSqlDispatchEvent()
{
$this->markTestSkipped('SQlite does not support ALTER Table.');
}

/**
* @group DDC-1845
*/
public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true));
$table->setPrimaryKey(array('"like"'));

$createTableSQL = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(
'CREATE TABLE test ("like" INTEGER NOT NULL, PRIMARY KEY("like"))',
$createTableSQL[0]
);

$this->assertEquals(
'ALTER TABLE test ADD PRIMARY KEY ("like")',
$this->_platform->getCreatePrimaryKeySQL($table->getIndex('primary'), 'test')
);
}
}

0 comments on commit baf30ae

Please sign in to comment.