diff options
author | Aaron Schulz <aschulz@wikimedia.org> | 2022-07-28 15:10:31 -0700 |
---|---|---|
committer | Aaron Schulz <aschulz@wikimedia.org> | 2023-05-26 19:01:45 -0700 |
commit | 924d1f0374551cd5af0bbe612595731d8c28b7fb (patch) | |
tree | a5e782cf252631fdf74029b720f28cf3e554209a /tests/phpunit/includes/db/DatabaseTestHelper.php | |
parent | 1afa5b109b65de2f44f53e0476a907b9d2429fc7 (diff) | |
download | mediawikicore-924d1f0374551cd5af0bbe612595731d8c28b7fb.tar.gz mediawikicore-924d1f0374551cd5af0bbe612595731d8c28b7fb.zip |
rdbms: make IDatabase::insertId() less fragile and more consistent
Track the insert ID value in Database, similar to the affected rows.
This makes it possible for subclasses to stash or override the value,
which is useful when emulating a write operation using multiple queries.
This includes the case of internal use of atomic sections, where the
COMMIT/RELEASE can reset the last_insert_id tracked in the PECL driver
itself.
Use separate methods and fields for "last query statement" information
and "last query method" information.
Make insertId() for SQLite and Postgres better match MySQL:
* Return 0 if the last query statement did not change any rows.
This helps protect against callers that fail to check affectedRows().
* Make it return the existing ROWID/SERIAL column when upsert() updates
an existing row. This adds a new getInsertIdColumnForUpsert() helper
function.
Directly use query() in doReplace() and doInsertSelectGeneric() to make
the affected row/ID logic easier to follow.
Improve insertId() and affectedRows() documentation.
Add more integration tests of row insertion methods.
Bug: T314100
Change-Id: I7d43a2e52260e66acb713554bb883f5f4a14d010
Diffstat (limited to 'tests/phpunit/includes/db/DatabaseTestHelper.php')
-rw-r--r-- | tests/phpunit/includes/db/DatabaseTestHelper.php | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/phpunit/includes/db/DatabaseTestHelper.php b/tests/phpunit/includes/db/DatabaseTestHelper.php index 4261a9851b23..1db68f4b6b3d 100644 --- a/tests/phpunit/includes/db/DatabaseTestHelper.php +++ b/tests/phpunit/includes/db/DatabaseTestHelper.php @@ -180,7 +180,7 @@ class DatabaseTestHelper extends Database { return true; } - public function insertId() { + protected function lastInsertId() { return -1; } @@ -238,7 +238,8 @@ class DatabaseTestHelper extends Database { if ( $this->nextResMapQueue ) { $this->lastResMap = array_shift( $this->nextResMapQueue ); if ( !$this->lastResMap['errno'] && $this->forcedAffectedCountQueue ) { - $this->affectedRowCount = array_shift( $this->forcedAffectedCountQueue ); + $count = array_shift( $this->forcedAffectedCountQueue ); + $this->lastQueryAffectedRows = $count; } } else { $this->lastResMap = [ 'res' => [], 'errno' => 0, 'error' => '' ]; |