Issue #3264471 by mcdruid, poker10: DatabaseUpdateTestCase::testExpressionUpdate assertion on number of affected rows fails in PostgreSQL
parent
6c46d1c310
commit
ed3e399822
|
@ -868,14 +868,30 @@ class DatabaseUpdateTestCase extends DatabaseTestCase {
|
||||||
->fields(array('age' => 1))
|
->fields(array('age' => 1))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
// Ensure that expressions are handled properly. This should set every
|
// 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
|
// record's age to a square of itself. The number of affected rows returned
|
||||||
// four records in the table since 1*1 = 1. That means only three records
|
// by db_update() will vary across different database engines and versions:
|
||||||
// are modified, so we should get back 3, not 4, from execute().
|
// - 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')
|
$num_rows = db_update('test')
|
||||||
->expression('age', 'age * age')
|
->expression('age', 'age * age')
|
||||||
->execute();
|
->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.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue