Add custom sqlite platform to set auto increment
This commit is contained in:
parent
ec2d7cff2f
commit
24a30c10d7
2 changed files with 36 additions and 0 deletions
|
@ -96,6 +96,7 @@ class ConnectionFactory {
|
|||
break;
|
||||
case 'sqlite3':
|
||||
$journalMode = $additionalConnectionParams['sqlite.journal_mode'];
|
||||
$additionalConnectionParams['platform'] = new SqlitePlatform();
|
||||
$eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode));
|
||||
break;
|
||||
}
|
||||
|
|
35
lib/private/db/sqliteplatform.php
Normal file
35
lib/private/db/sqliteplatform.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OC\DB;
|
||||
|
||||
class SqlitePlatform extends \Doctrine\DBAL\Platforms\SqlitePlatform {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getColumnDeclarationSQL($name, array $field) {
|
||||
$def = parent::getColumnDeclarationSQL($name, $field);
|
||||
if (!empty($field['autoincrement'])) {
|
||||
$def .= ' PRIMARY KEY AUTOINCREMENT';
|
||||
}
|
||||
return $def;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function _getCreateTableSQL($name, array $columns, array $options = array()){
|
||||
// if auto increment is set the column is already defined as primary key
|
||||
foreach ($columns as $column) {
|
||||
if (!empty($column['autoincrement'])) {
|
||||
$options['primary'] = null;
|
||||
}
|
||||
}
|
||||
return parent::_getCreateTableSQL($name, $columns, $options);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue