Skip to content

Commit

Permalink
Fixed pg not supporting aggretated functions wth "FOR UPDATE"
Browse files Browse the repository at this point in the history
  • Loading branch information
kimhemsoe committed Jul 1, 2012
1 parent 024410a commit 03840fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Doctrine/DBAL/Connection.php
Expand Up @@ -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);
Expand Down

0 comments on commit 03840fc

Please sign in to comment.