diff options
Diffstat (limited to 'includes/database')
-rw-r--r-- | includes/database/database.inc | 8 | ||||
-rw-r--r-- | includes/database/mysql/query.inc | 6 | ||||
-rw-r--r-- | includes/database/query.inc | 5 |
3 files changed, 19 insertions, 0 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc index eecb8f88c..043515548 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -1170,6 +1170,14 @@ abstract class Database { class TransactionsNotSupportedException extends PDOException { } /** + * Exception thrown for merge queries that do not make semantic sense. + * + * There are many ways that a merge query could be malformed. They should all + * throw this exception and set an appropriately descriptive message. + */ +class InvalidMergeQueryException extends Exception {} + +/** * A wrapper class for creating and managing database transactions. * * Not all databases or database configurations support transactions. For diff --git a/includes/database/mysql/query.inc b/includes/database/mysql/query.inc index d48681316..751137602 100644 --- a/includes/database/mysql/query.inc +++ b/includes/database/mysql/query.inc @@ -80,6 +80,12 @@ class InsertQuery_mysql extends InsertQuery { class MergeQuery_mysql extends MergeQuery { public function execute() { + + // A merge query without any key field is invalid. + if (count($this->keyFields) == 0) { + throw new InvalidMergeQueryException("You need to specify key fields before executing a merge query"); + } + // Set defaults. if ($this->updateFields) { $update_fields = $this->updateFields; diff --git a/includes/database/query.inc b/includes/database/query.inc index 396b59afb..c8e312dec 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -635,6 +635,11 @@ class MergeQuery extends Query { public function execute() { + // A merge query without any key field is invalid. + if (count($this->keyFields) == 0) { + throw new InvalidMergeQueryException("You need to specify key fields before executing a merge query"); + } + // In the degenerate case of this query type, we have to run multiple // queries as there is no universal single-query mechanism that will work. // Our degenerate case is not designed for performance efficiency but |