From bcbf90a8374a379c71689b3372b86a0981d9c420 Mon Sep 17 00:00:00 2001 From: Michal Kleiner <michal.kleiner@chrometoaster.com> Date: Mon, 16 Sep 2019 14:33:20 +1200 Subject: [PATCH] NEW Introduce supported database transaction mode check --- src/ORM/Connect/Database.php | 14 ++++++++++++++ tests/php/ORM/TransactionTest.php | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ORM/Connect/Database.php b/src/ORM/Connect/Database.php index ad92bf174..a129ff085 100644 --- a/src/ORM/Connect/Database.php +++ b/src/ORM/Connect/Database.php @@ -656,6 +656,20 @@ abstract class Database 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 * diff --git a/tests/php/ORM/TransactionTest.php b/tests/php/ORM/TransactionTest.php index c6e892f28..075c788d4 100644 --- a/tests/php/ORM/TransactionTest.php +++ b/tests/php/ORM/TransactionTest.php @@ -157,7 +157,12 @@ class TransactionTest extends SapphireTest public function testReadOnlyTransaction() { 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; }