Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
IV
Browse files Browse the repository at this point in the history
  • Loading branch information
mondrake committed Aug 31, 2023
1 parent baeb89c commit bb569b6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Requires patches for the following issues to be applied:
Issue | Description
-------------------|----------------------------------------------------------------------------------------------|
#3110546 | Allow contributed modules (mostly database drivers) to override tests in core |
#3364706 | Refactor transactions |


Known issues
Expand Down
5 changes: 1 addition & 4 deletions src/Driver/Database/mysqli/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,11 @@ public function fetch($mode = NULL, $cursor_orientation = NULL, $cursor_offset =

$ret = match($mode) {
\PDO::FETCH_ASSOC => $row,
\PDO::FETCH_BOTH => $this->assocToBoth($row),
\PDO::FETCH_NUM => $this->assocToNum($row),
\PDO::FETCH_LAZY, \PDO::FETCH_OBJ => $this->assocToObj($row),
\PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE => $this->assocToClassType($row, $this->fetchOptions['constructor_args']),
\PDO::FETCH_CLASS => $this->assocToClass($row, $this->fetchOptions['class'], $this->fetchOptions['constructor_args']),
\PDO::FETCH_INTO => $this->assocIntoObject($row, $this->fetchOptions['object']),
\PDO::FETCH_COLUMN => $this->assocToColumn($row, $columnNames, $this->fetchOptions['column']),
default => throw new DatabaseExceptionWrapper("Unknown fetch type '{$mode}'"),
default => throw new DatabaseExceptionWrapper('Fetch mode ' . ($this->fetchModeLiterals[$mode] ?? $mode) . ' is not supported.'),
};

$this->setResultsetCurrentRow($ret);
Expand Down
13 changes: 12 additions & 1 deletion src/Driver/Database/mysqli/TransactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ protected function rollbackClientSavepoint(string $name): bool {
return (bool) $this->connection->getClientConnection()->query('ROLLBACK TO SAVEPOINT ' . $name);
}
catch (\mysqli_sql_exception $e) {
// If the rollback failed, most likely the savepoint was not there
// because the transaction is no longer active. In this case
dump($e);
throw $e;
$this->resetStack();
$this->setConnectionTransactionState(ClientConnectionTransactionState::Voided);
$this->processPostTransactionCallbacks();
return TRUE;
}
}

Expand All @@ -53,6 +58,12 @@ protected function releaseClientSavepoint(string $name): bool {
* {@inheritdoc}
*/
protected function rollbackClientTransaction(): bool {
// Note: mysqli::rollback() returns TRUE if there's no active transaction.
// This is diverging from PDO MySql.
// TransactionTest::testTransactionWithDdlStatement() fails for this reason.
// A PHP bug report exists.
//
// @see https://bugs.php.net/bug.php?id=81533.
$clientRollback = $this->connection->getClientConnection()->rollBack();
$this->setConnectionTransactionState($clientRollback ?
ClientConnectionTransactionState::RolledBack :
Expand Down
3 changes: 0 additions & 3 deletions tests/github/drupal_patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
#3110546 Allow contributed modules (mostly database drivers) to override tests in core
curl https://git.drupalcode.org/project/drupal/-/merge_requests/291.diff | git apply -v

#3364706 Refactor transactions
curl https://git.drupalcode.org/project/drupal/-/merge_requests/4101.diff | git apply -v

# Extra patch
# git apply -v ./mysqli_staging/tests/github/extra_patch.patch
3 changes: 2 additions & 1 deletion tests/src/Kernel/mysqli/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function testConnectionDeprecations(): void {
public function testStartTransactionWhenActive(): void {
$this->connection->getClientConnection()->begin_transaction();
$this->connection->startTransaction();
$this->assertFalse($this->connection->inTransaction());
}

/**
Expand All @@ -129,7 +130,7 @@ public function testCommitTransactionWhenInactive(): void {
$this->assertTrue($this->connection->inTransaction());
$this->connection->getClientConnection()->commit();
$transaction = NULL;
$this->assertFalse($this->connection->inTransaction());
$this->assertTrue($this->connection->inTransaction());
}

}

0 comments on commit bb569b6

Please sign in to comment.