From 44c8391d327f589fb5e96bb7bbe0c08db1611441 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 13 Nov 2008 21:08:16 +0000 Subject: - Patch #321100 by hswong3i: empty insert statements are better handled now. Comes with tests. --- includes/database/query.inc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'includes/database/query.inc') diff --git a/includes/database/query.inc b/includes/database/query.inc index 5ecc8ce6e..a5b2ae313 100644 --- a/includes/database/query.inc +++ b/includes/database/query.inc @@ -382,7 +382,9 @@ class InsertQuery extends Query { * was given multiple sets of values to insert, the return value is * undefined. If the query is flagged "delayed", then the insert ID * won't be created until later when the query actually runs so the - * return value is also undefined. + * return value is also undefined. If no fields are specified, this + * method will do nothing and return NULL. That makes it safe to use + * in multi-insert loops. */ public function execute() { @@ -394,6 +396,10 @@ class InsertQuery extends Query { throw new PDOException('You may not specify the same field to have a value and a schema-default value.'); } + if (count($this->insertFields) + count($this->defaultFields) == 0) { + return NULL; + } + // Each insert happens in its own query in the degenerate case. However, // we wrap it in a transaction so that it is atomic where possible. On many // databases, such as SQLite, this is also a notable performance boost. -- cgit v1.2.3