summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-12-26 14:23:38 +0000
committerDries Buytaert <dries@buytaert.net>2008-12-26 14:23:38 +0000
commit0d100b57dcffe54ec7f46d8f577a4c26fcf34202 (patch)
treeffcfb6c4cb5e1f9481479620c87b37a2c7b6ebec /includes
parentfc063806de3ded56d1c3d78a49e8a60de7a7fe1c (diff)
downloadbrdo-0d100b57dcffe54ec7f46d8f577a4c26fcf34202.tar.gz
brdo-0d100b57dcffe54ec7f46d8f577a4c26fcf34202.tar.bz2
- Patch #332002 by Crell et al: MergeQuery should refuse to execute if there are no key fields. With tests.
Diffstat (limited to 'includes')
-rw-r--r--includes/database/database.inc8
-rw-r--r--includes/database/mysql/query.inc6
-rw-r--r--includes/database/query.inc5
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