From 9d6182d8d00b99a608b49ae47a5ccd03187802fe Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 11 Oct 2009 13:43:37 +0000 Subject: - Patch #597556 by Berdir: return status to indicate executed query in MergeQuery::execute(). --- includes/database/query.inc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'includes/database/query.inc') 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. -- cgit v1.2.3