summaryrefslogtreecommitdiff
path: root/includes/database/query.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-10-11 13:43:37 +0000
committerDries Buytaert <dries@buytaert.net>2009-10-11 13:43:37 +0000
commit9d6182d8d00b99a608b49ae47a5ccd03187802fe (patch)
treed5bf25b43fdcb8746f65fa7b9cda11e083924a53 /includes/database/query.inc
parent19089633f62f8b9b61e79ccee32850c155f6716e (diff)
downloadbrdo-9d6182d8d00b99a608b49ae47a5ccd03187802fe.tar.gz
brdo-9d6182d8d00b99a608b49ae47a5ccd03187802fe.tar.bz2
- Patch #597556 by Berdir: return status to indicate executed query in MergeQuery::execute().
Diffstat (limited to 'includes/database/query.inc')
-rw-r--r--includes/database/query.inc19
1 files changed, 19 insertions, 0 deletions
diff --git a/includes/database/query.inc b/includes/database/query.inc
index 87b903d96..98723496d 100644
--- a/includes/database/query.inc
+++ b/includes/database/query.inc
@@ -548,6 +548,15 @@ class InsertQuery extends Query {
* General class for an abstracted MERGE operation.
*/
class MergeQuery extends Query {
+ /**
+ * Returned by execute() if an INSERT query has been executed.
+ */
+ const STATUS_INSERT = 1;
+
+ /**
+ * Returned by execute() if an UPDATE query has been executed.
+ */
+ const STATUS_UPDATE = 2;
/**
* The table on which to insert.
@@ -761,6 +770,14 @@ class MergeQuery extends Query {
return TRUE;
}
+ /**
+ * Run the MERGE query against the database.
+ *
+ * @return
+ * A status indicating the executed operation:
+ * - MergeQuery::STATUS_INSERT for an INSERT operation.
+ * - MergeQuery::STATUS_UPDATE for an UPDATE operation.
+ */
public function execute() {
// If validation fails, simply return NULL.
// Note that validation routines in preExecute() may throw exceptions instead.
@@ -813,12 +830,14 @@ class MergeQuery extends Query {
$update->expression($field, $expression['expression'], $expression['arguments']);
}
$update->execute();
+ return MergeQuery::STATUS_UPDATE;
}
}
else {
// If there is no existing record, run an insert query.
$insert_fields = $this->insertFields + $this->keyFields;
$this->connection->insert($this->table, $this->queryOptions)->fields($insert_fields)->execute();
+ return MergeQuery::STATUS_INSERT;
}
// Transaction commits here where $transaction looses scope.