Loading modules/simpletest/tests/database_test.test +20 −4 Original line number Diff line number Diff line Loading @@ -869,13 +869,29 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->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(). // 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.'); } } Loading Loading
modules/simpletest/tests/database_test.test +20 −4 Original line number Diff line number Diff line Loading @@ -869,13 +869,29 @@ class DatabaseUpdateTestCase extends DatabaseTestCase { ->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(). // 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.'); } } Loading