Remove broken SQLite auto-increment and fix composite primary keys

* The old implementation produced invalid SQLite statements for tables with
  a composite primary key, as SQLite cannot have more than one primary key
  clause and autoincrement can only be declared on a single column
* There is currently no way to tell from its pragma if an SQLite column
  auto-increments, therefore enabling it on all primary keys is not accurate
* SQLite primary keys auto-increment anyway (but slightly differently from an
  actual auto-increment column -- not guaranteed unique)
parent 5e86f6e3
......@@ -254,10 +254,7 @@ class SqlitePlatform extends AbstractPlatform
*/
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
$autoinc = ! empty($columnDef['autoincrement']) ? ' AUTOINCREMENT' : '';
$pk = ! empty($columnDef['primary']) && ! empty($autoinc) ? ' PRIMARY KEY' : '';
return 'INTEGER' . $pk . $autoinc;
return 'INTEGER';
}
/**
......@@ -294,15 +291,7 @@ class SqlitePlatform extends AbstractPlatform
$name = str_replace(".", "__", $name);
$queryFields = $this->getColumnDeclarationListSQL($columns);
$autoinc = false;
foreach($columns as $field) {
if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = true;
break;
}
}
if ( ! $autoinc && isset($options['primary']) && ! empty($options['primary'])) {
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).')';
......
......@@ -174,7 +174,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
'default' => $default,
'precision' => $precision,
'scale' => $scale,
'autoincrement' => (bool) $tableColumn['pk'],
'autoincrement' => false,
);
return new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
......
Subproject commit d6e4c8b22af9800db4fd9d679ce98538da028168
Subproject commit d599286518ef739afed05b4f29760ac44d275233
......@@ -35,4 +35,12 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
$this->_sm->renameTable('oldname', 'newname');
}
public function testAutoincrementDetection()
{
$this->markTestSkipped(
'There is currently no reliable way to determine whether an SQLite column is marked as '
. 'auto-increment. So, while it does support a single identity column, we cannot with '
. 'certainty determine which it is.');
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment