Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'busy_timeout' => null,
'journal_mode' => null,
'synchronous' => null,
'transaction_mode' => 'DEFERRED',
],

'mysql' => [
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Database/Concerns/ManagesTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace Illuminate\Database\Concerns;

use Closure;
use Illuminate\Database\Connection;
use Illuminate\Database\DeadlockException;
use RuntimeException;
use Throwable;

/**
* @mixin Connection
*/
trait ManagesTransactions
{
/**
Expand Down Expand Up @@ -148,7 +152,7 @@ protected function createTransaction()
$this->reconnectIfMissingConnection();

try {
$this->getPdo()->beginTransaction();
$this->executeBeginTransactionStatement();
} catch (Throwable $e) {
$this->handleBeginTransactionException($e);
}
Expand Down Expand Up @@ -184,7 +188,7 @@ protected function handleBeginTransactionException(Throwable $e)
if ($this->causedByLostConnection($e)) {
$this->reconnect();

$this->getPdo()->beginTransaction();
$this->executeBeginTransactionStatement();
} else {
throw $e;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,16 @@ public function unsetEventDispatcher()
$this->events = null;
}

/**
* Run the statement to start a new transaction.
*
* @return void
*/
protected function executeBeginTransactionStatement()
{
$this->getPdo()->beginTransaction();
}

/**
* Set the transaction manager instance on the connection.
*
Expand Down
18 changes: 18 additions & 0 deletions src/Illuminate/Database/SQLiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ public function getDriverTitle()
return 'SQLite';
}

/**
* Run the statement to start a new transaction.
*
* @return void
*/
protected function executeBeginTransactionStatement()
{
if (version_compare(PHP_VERSION, '8.4.0') >= 0) {
$mode = $this->getConfig('transaction_mode') ?? 'DEFERRED';

$this->getPdo()->exec("BEGIN {$mode} TRANSACTION");

return;
}

$this->getPdo()->beginTransaction();
}

/**
* Escape a binary value for safe SQL embedding.
*
Expand Down