Issue #3264471 by mcdruid, poker10: DatabaseUpdateTestCase::testExpressionUpdate assertion on number of affected rows fails in PostgreSQL

merge-requests/736/merge
mcdruid 2022-02-21 15:02:18 +00:00
parent 6c46d1c310
commit ed3e399822
1 changed files with 21 additions and 5 deletions

View File

@ -868,14 +868,30 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
->fields(array('age' => 1))
->execute();
// Ensure that expressions are handled properly. This should set every
// record's age to a square of itself, which will change only three of the
// four records in the table since 1*1 = 1. That means only three records
// are modified, so we should get back 3, not 4, from execute().
// Ensure that expressions are handled properly. This should set every
// record's age to a square of itself. The number of affected rows returned
// by db_update() will vary across different database engines and versions:
// - MySQL / InnoDB: changed rows only
// - MySQL / MyISAM: changed rows only
// - PostgreSQL: all rows matched by the query
// - SQLite: changed rows only (see workaround in UpdateQuery_sqlite)
// All database engines will change only three of the four records in the
// table since 1*1 = 1. However, the pgsql driver will return the number of
// rows matched rather than the number changed.
// @see https://www.drupal.org/project/drupal/issues/805858
// @see https://www.drupal.org/project/drupal/issues/3264471
$connection = Database::getConnection()->getConnectionOptions();
$expected_rows = 3;
if ($connection['driver'] === 'pgsql') {
$expected_rows ++;
}
$num_rows = db_update('test')
->expression('age', 'age * age')
->execute();
$this->assertIdentical($num_rows, 3, 'Number of affected rows are returned.');
$this->assertIdentical($num_rows, $expected_rows, 'Number of affected rows are returned.');
$saved_name = db_query('SELECT name FROM {test} WHERE age = :age', array(':age' => pow(26, 2)))->fetchField();
$this->assertIdentical('Paul', $saved_name, 'Successfully updated values using an algebraic expression.');
}
}