diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
index 9b9cf97..8c2a34a 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
@@ -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']);
diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Update.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Update.php
index 5c93433..dd8a72a 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Update.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Update.php
@@ -65,7 +65,8 @@ public function execute() {
 
     $options = $this->queryOptions;
     $options['already_prepared'] = TRUE;
-    $this->connection->query($stmt, $options);
+    $options['return'] = Database::RETURN_AFFECTED;
+    $this->connection->query($stmt, array(), $options);
 
     return $stmt->rowCount();
   }
diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
index edd54f3..137e23c 100644
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
@@ -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,
       ));
