From 03840fcbbec51388d84f6a212571b8556ebcb5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Hems=C3=B8=20Rasmussen?= Date: Sun, 1 Jul 2012 23:52:58 +0200 Subject: [PATCH] Fixed pg not supporting aggretated functions wth "FOR UPDATE" --- lib/Doctrine/DBAL/Connection.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 117a5f86f9c..f06dfe50c0c 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -555,12 +555,16 @@ public function upsert($tableName, array $data, array $identifier, array $types list ($sql, $params, $types) = $this->_platform->getUpsertSql($tableName, $data, $identifier, $types); return $this->executeUpdate($sql, $params, $types); } else { - $sql = 'SELECT COUNT(*) FROM ' . $tableName + $sql = 'SELECT ' . implode(', ', array_keys($identifier)) . ' FROM ' . $tableName . ' WHERE ' . implode(' = ? AND ', array_keys($identifier)) . ' = ?' . ' ' . $this->_platform->getWriteLockSQL(); - if ($this->fetchColumn($sql, array_values($identifier))) { + $stmt = $this->executeQuery($sql, array_values($identifier)); + $haveRows = (bool)$stmt->fetch(PDO::FETCH_NUM); + $stmt->closeCursor(); + + if ($haveRows) { return $this->update($tableName, $data, $identifier, $types); } else { return $this->insert($tableName, $data, $types);