Documentation conflict re: affected rows vs. matched rows

Created on 9 November 2021, almost 3 years ago
Updated 28 January 2023, over 1 year ago

Problem/Motivation

Comments in Drupal\Core\Database\Connection state:

Database::RETURN_AFFECTED: Return the number of rows affected by an UPDATE or DELETE query. Be aware that means the number of rows actually changed, not the number of rows matched by the WHERE clause.

Meanwhile Drupal\Core\Database\Driver\mysql\Connection states:

Make sure MySQL returns all matched rows on update queries including rows that actually didn't have to be updated because the values didn't change. This matches common behavior among other database systems.

and enables PDO::MYSQL_ATTR_FOUND_ROWS, which causes the number of matched rows to be returned rather than the number of affected rows.

Steps to reproduce

Something like ./vendor/bin/drush php:eval 'echo Drupal::database()->update("users")->fields(["uid" => 0])->condition("uid", 0)->execute()' returns 1 row matched/found, even though 0 rows were affected/changed (on MySQL, sqlite and postgres).

Proposed resolution

Update documentation to explain that number of rows matched is returned, not number of rows affected?

πŸ› Bug report
Status

Fixed

Version

9.5

Component
DatabaseΒ  β†’

Last updated 1 minute ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024