Commit 44278128 authored by webchick's avatar webchick
Browse files

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

Issue #2167507 by andypost, chx, sun, dcrocks: Fix rowCount query usage in pgsql and sqlite drivers.
parent 7a221e58
......@@ -130,9 +130,9 @@ public function query($query, array $args = array(), $options = array()) {
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']);
......
......@@ -65,8 +65,8 @@ public function execute() {
$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);
}
}
......@@ -310,11 +310,13 @@ public function nextId($existing_id = 0) {
// 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,
));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment