summaryrefslogtreecommitdiff
path: root/includes/database/sqlite
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-09-24 02:05:55 +0000
committerDries Buytaert <dries@buytaert.net>2010-09-24 02:05:55 +0000
commite0032eeee61f0cb83dbcd7e410bd85f8226b7ec7 (patch)
tree21057bd3cbbe26cdcdf617fa16dbd960fca94a55 /includes/database/sqlite
parent5e1f9113e966e7766726416083ad9a5518e56218 (diff)
downloadbrdo-e0032eeee61f0cb83dbcd7e410bd85f8226b7ec7.tar.gz
brdo-e0032eeee61f0cb83dbcd7e410bd85f8226b7ec7.tar.bz2
- Patch #844186 by chx: clarify merge queries.
Diffstat (limited to 'includes/database/sqlite')
-rw-r--r--includes/database/sqlite/query.inc69
1 files changed, 10 insertions, 59 deletions
diff --git a/includes/database/sqlite/query.inc b/includes/database/sqlite/query.inc
index 1e0eed0e5..c79da0328 100644
--- a/includes/database/sqlite/query.inc
+++ b/includes/database/sqlite/query.inc
@@ -12,6 +12,16 @@
*/
/**
+ * SQLite specific query builder for SELECT statements.
+ */
+class SelectQuery_sqlite extends SelectQuery {
+ public function forUpdate($set = TRUE) {
+ // SQLite does not support FOR UPDATE so nothing to do.
+ return $this;
+ }
+}
+
+/**
* SQLite specific implementation of InsertQuery.
*
* We ignore all the default fields and use the clever SQLite syntax:
@@ -119,65 +129,6 @@ class UpdateQuery_sqlite extends UpdateQuery {
}
/**
- * SQLite specific implementation of MergeQuery.
- *
- * SQLite doesn't support row-level locking, but acquire locks on the whole
- * database file. We implement MergeQuery using a different strategy:
- * - UPDATE xxx WHERE <key condition>
- * - if the previous query hasn't matched, INSERT
- *
- * The first UPDATE query will acquire a RESERVED lock on the database.
- */
-class MergeQuery_sqlite extends MergeQuery {
- public function execute() {
- // If validation fails, simply return NULL.
- // Note that validation routines in preExecute() may throw exceptions instead.
- if (!$this->preExecute()) {
- return NULL;
- }
-
- // Wrap multiple queries in a transaction.
- $transaction = $this->connection->startTransaction();
-
- if ($this->updateFields) {
- $update_fields = $this->updateFields;
- }
- else {
- $update_fields = $this->insertFields;
- // If there are no exclude fields, this is a no-op.
- foreach ($this->excludeFields as $exclude_field) {
- unset($update_fields[$exclude_field]);
- }
- }
-
- // The update fields are empty, fill them with dummy data.
- if (!$update_fields && !$this->expressionFields) {
- $update_fields = array_slice($this->keyFields, 0, 1);
- }
-
- // Start with an update query, this acquires a RESERVED lock on the database.
- // Use the SQLite-specific 'sqlite_return_matched_rows' query option to
- // return the number of rows matched by that query, not modified by it.
- $update = $this->connection->update($this->table, array('sqlite_return_matched_rows' => TRUE) + $this->queryOptions)->fields($update_fields);
-
- foreach ($this->keyFields as $field => $value) {
- $update->condition($field, $value);
- }
- foreach ($this->expressionFields as $field => $expression) {
- $update->expression($field, $expression['expression'], $expression['arguments']);
- }
- if ($update->execute()) {
- return MergeQuery::STATUS_UPDATE;
- }
-
- // The UPDATE query failed to match rows, proceed with an INSERT.
- $insert_fields = $this->insertFields + $this->keyFields;
- $this->connection->insert($this->table, $this->queryOptions)->fields($insert_fields)->execute();
- return MergeQuery::STATUS_INSERT;
- }
-}
-
-/**
* SQLite specific implementation of DeleteQuery.
*
* When the WHERE is omitted from a DELETE statement and the table being deleted