File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed
Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 4141 'busy_timeout ' => null ,
4242 'journal_mode ' => null ,
4343 'synchronous ' => null ,
44+ 'transaction_mode ' => 'DEFERRED ' ,
4445 ],
4546
4647 'mysql ' => [
Original file line number Diff line number Diff line change 33namespace Illuminate \Database \Concerns ;
44
55use Closure ;
6+ use Illuminate \Database \Connection ;
67use Illuminate \Database \DeadlockException ;
78use RuntimeException ;
89use Throwable ;
910
11+ /**
12+ * @mixin Connection
13+ */
1014trait ManagesTransactions
1115{
1216 /**
@@ -148,7 +152,7 @@ protected function createTransaction()
148152 $ this ->reconnectIfMissingConnection ();
149153
150154 try {
151- $ this ->getPdo ()-> beginTransaction ();
155+ $ this ->executeBeginTransactionStatement ();
152156 } catch (Throwable $ e ) {
153157 $ this ->handleBeginTransactionException ($ e );
154158 }
@@ -184,7 +188,7 @@ protected function handleBeginTransactionException(Throwable $e)
184188 if ($ this ->causedByLostConnection ($ e )) {
185189 $ this ->reconnect ();
186190
187- $ this ->getPdo ()-> beginTransaction ();
191+ $ this ->executeBeginTransactionStatement ();
188192 } else {
189193 throw $ e ;
190194 }
Original file line number Diff line number Diff line change @@ -1470,6 +1470,16 @@ public function unsetEventDispatcher()
14701470 $ this ->events = null ;
14711471 }
14721472
1473+ /**
1474+ * Run the statement to start a new transaction.
1475+ *
1476+ * @return void
1477+ */
1478+ protected function executeBeginTransactionStatement ()
1479+ {
1480+ $ this ->getPdo ()->beginTransaction ();
1481+ }
1482+
14731483 /**
14741484 * Set the transaction manager instance on the connection.
14751485 *
Original file line number Diff line number Diff line change @@ -20,6 +20,24 @@ public function getDriverTitle()
2020 return 'SQLite ' ;
2121 }
2222
23+ /**
24+ * Run the statement to start a new transaction.
25+ *
26+ * @return void
27+ */
28+ protected function executeBeginTransactionStatement ()
29+ {
30+ if (version_compare (PHP_VERSION , '8.4.0 ' ) >= 0 ) {
31+ $ mode = $ this ->getConfig ('transaction_mode ' ) ?? 'DEFERRED ' ;
32+
33+ $ this ->getPdo ()->exec ("BEGIN {$ mode } TRANSACTION " );
34+
35+ return ;
36+ }
37+
38+ $ this ->getPdo ()->beginTransaction ();
39+ }
40+
2341 /**
2442 * Escape a binary value for safe SQL embedding.
2543 *
You can’t perform that action at this time.
0 commit comments