Issue #2167507 by andypost, chx, sun, dcrocks: Fix rowCount query usage in pgsql and sqlite drivers.

8.0.x
webchick 2014-01-13 10:00:25 -08:00
parent 7a221e58b1
commit 4427812833
3 changed files with 10 additions and 8 deletions

View File

@ -130,9 +130,9 @@ class Connection extends DatabaseConnection {
switch ($options['return']) {
case Database::RETURN_STATEMENT:
$stmt->allowRowCount = FALSE;
return $stmt;
case Database::RETURN_AFFECTED:
$stmt->allowRowCount = TRUE;
return $stmt->rowCount();
case Database::RETURN_INSERT_ID:
return $this->connection->lastInsertId($options['sequence_name']);

View File

@ -65,8 +65,8 @@ class Update extends QueryUpdate {
$options = $this->queryOptions;
$options['already_prepared'] = TRUE;
$this->connection->query($stmt, $options);
return $stmt->rowCount();
$options['return'] = Database::RETURN_AFFECTED;
return $this->connection->query($stmt, array(), $options);
}
}

View File

@ -310,11 +310,13 @@ class Connection extends DatabaseConnection {
// override nextId. However, this is unlikely as we deal with short strings
// and integers and no known databases require special handling for those
// simple cases. If another transaction wants to write the same row, it will
// wait until this transaction commits.
$stmt = $this->query('UPDATE {sequences} SET value = GREATEST(value, :existing_id) + 1', array(
// wait until this transaction commits. Also, the return value needs to be
// set to RETURN_AFFECTED as if it were a real update() query otherwise it
// is not possible to get the row count properly.
$affected = $this->query('UPDATE {sequences} SET value = GREATEST(value, :existing_id) + 1', array(
':existing_id' => $existing_id,
));
if (!$stmt->rowCount()) {
), array('return' => Database::RETURN_AFFECTED));
if (!$affected) {
$this->query('INSERT INTO {sequences} (value) VALUES (:existing_id + 1)', array(
':existing_id' => $existing_id,
));