summaryrefslogtreecommitdiff
path: root/includes/database/sqlite
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-07 04:51:26 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-07 04:51:26 +0000
commit37fcdbc67cd5591107c93016d1d3bb109be5e9e6 (patch)
tree9f0ffd5a6d54456e97e53b57f3de29b0966a4bbc /includes/database/sqlite
parent39f4d7245c0cb5e258b0ca6ec7fd31df6699408d (diff)
downloadbrdo-37fcdbc67cd5591107c93016d1d3bb109be5e9e6.tar.gz
brdo-37fcdbc67cd5591107c93016d1d3bb109be5e9e6.tar.bz2
#633678 by Josh Waihi, chx, Crell, David Strauss, and Damien Tournoud: Make sequence API work on non-MySQL databases.
Diffstat (limited to 'includes/database/sqlite')
-rw-r--r--includes/database/sqlite/database.inc21
1 files changed, 21 insertions, 0 deletions
diff --git a/includes/database/sqlite/database.inc b/includes/database/sqlite/database.inc
index e762a6ba7..eaeacb32d 100644
--- a/includes/database/sqlite/database.inc
+++ b/includes/database/sqlite/database.inc
@@ -167,6 +167,27 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
// DatabaseStatement_sqlite::execute() and cannot be cached.
return $this->prepare($this->prefixTables($query));
}
+
+ public function nextId($existing_id = 0) {
+ $transaction = $this->startTransaction();
+ // We can safely use literal queries here instead of the slower query
+ // builder because if a given database breaks here then it can simply
+ // override nextId. However, this is unlikely as we deal with short strings
+ // and integers and no known databases require special handling for those
+ // simple cases. If another transaction wants to write the same row, it will
+ // wait until this transaction commits.
+ $stmt = $this->query('UPDATE {sequences} SET value = GREATEST(value, :existing_id) + 1', array(
+ ':existing_id' => $existing_id,
+ ));
+ if (!$stmt->rowCount()) {
+ $this->query('INSERT INTO {sequences} (value) VALUES (:existing_id + 1)', array(
+ ':existing_id' => $existing_id,
+ ));
+ }
+ // The transaction gets committed when the transaction object gets destroyed
+ // because it gets out of scope.
+ return $new_value;
+ }
}
/**