mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9240 from chrometoasters/pulls/db-readonly-transactions-support
NEW Introduce supported database transaction mode check
This commit is contained in:
commit
af6644f762
@ -656,6 +656,20 @@ abstract class Database
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the used database supports given transactionMode as an argument to startTransaction()
|
||||||
|
* If transactions are completely unsupported, returns false.
|
||||||
|
*
|
||||||
|
* @param string $mode
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function supportsTransactionMode(string $mode): bool
|
||||||
|
{
|
||||||
|
// Default implementation: assume all modes are a supported.
|
||||||
|
return $this->supportsTransactions();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke $callback within a transaction
|
* Invoke $callback within a transaction
|
||||||
*
|
*
|
||||||
|
@ -157,7 +157,12 @@ class TransactionTest extends SapphireTest
|
|||||||
public function testReadOnlyTransaction()
|
public function testReadOnlyTransaction()
|
||||||
{
|
{
|
||||||
if (!DB::get_conn()->supportsTransactions()) {
|
if (!DB::get_conn()->supportsTransactions()) {
|
||||||
$this->markTestSkipped('Current database is doesn\'t support transactions');
|
$this->markTestSkipped('Current database doesn\'t support transactions');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DB::get_conn()->supportsTransactionMode('READ ONLY')) {
|
||||||
|
$this->markTestSkipped('Current database doesn\'t support READ ONLY transactions');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user