summaryrefslogtreecommitdiffstats
path: root/lib/private/db
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2015-03-04 14:30:07 +0100
committerVincent Petry <pvince81@owncloud.com>2015-03-25 18:33:21 +0100
commit24a30c10d7a8f2e1bd2e5f57c6291d809dfdbb0c (patch)
tree7b487ef5cb4dbb5b6739b5126afe24b38ade6056 /lib/private/db
parentec2d7cff2f36fb37ea6348022bbba09430ac3b9f (diff)
downloadnextcloud-server-24a30c10d7a8f2e1bd2e5f57c6291d809dfdbb0c.tar.gz
nextcloud-server-24a30c10d7a8f2e1bd2e5f57c6291d809dfdbb0c.zip
Add custom sqlite platform to set auto increment
Diffstat (limited to 'lib/private/db')
-rw-r--r--lib/private/db/connectionfactory.php1
-rw-r--r--lib/private/db/sqliteplatform.php35
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/private/db/connectionfactory.php b/lib/private/db/connectionfactory.php
index 44b598dcda0..c488bf82d1f 100644
--- a/lib/private/db/connectionfactory.php
+++ b/lib/private/db/connectionfactory.php
@@ -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;
}
diff --git a/lib/private/db/sqliteplatform.php b/lib/private/db/sqliteplatform.php
new file mode 100644
index 00000000000..b2eec7dd7bf
--- /dev/null
+++ b/lib/private/db/sqliteplatform.php
@@ -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);
+ }
+}