#715108: dumb out merge queries to fit the lowest denominator. MyISAM, I'm looking at you. From: Damien Tournoud --- database/query.inc | 27 +++++++-------------------- 1 files changed, 7 insertions(+), 20 deletions(-) diff --git includes/database/query.inc includes/database/query.inc index 46e7045..dc4915f 100644 --- includes/database/query.inc +++ includes/database/query.inc @@ -799,21 +799,14 @@ class MergeQuery extends Query { // Wrap multiple queries in a transaction, if the database supports it. $transaction = $this->connection->startTransaction(); - // Manually check if the record already exists. - $select = $this->connection->select($this->table); - foreach ($this->keyFields as $field => $value) { - $select->condition($field, $value); + try { + // Try to insert first. + $insert_fields = $this->insertFields + $this->keyFields; + $this->connection->insert($this->table, $this->queryOptions)->fields($insert_fields)->execute(); + return MergeQuery::STATUS_INSERT; } - - $select = $select->countQuery(); - $sql = (string)$select; - $arguments = $select->getArguments(); - $num_existing = db_query($sql, $arguments)->fetchField(); - - - if ($num_existing) { - // If there is already an existing record, run an update query. - + catch (PDOException $e) { + // Or else update. if ($this->updateFields) { $update_fields = $this->updateFields; } @@ -837,12 +830,6 @@ class MergeQuery extends Query { 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. }