Skip to content

Commit 5813acb

Browse files
mikedoddmikedoddpropeltaylorotwell
authored
Add isolation levels to SQL Server Connector (#45023)
* Add isolation levels to SQL Server Connector * Add isolation levels to SQL Server Connector * Add isolation levels to SQL Server Connector * Add isolation levels to SQL Server Connector * Update SqlServerConnector.php Co-authored-by: Mike Dodd <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent e19dbdb commit 5813acb

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/Illuminate/Database/Connectors/SqlServerConnector.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,31 @@ public function connect(array $config)
2929
{
3030
$options = $this->getOptions($config);
3131

32-
return $this->createConnection($this->getDsn($config), $config, $options);
32+
$connection = $this->createConnection($this->getDsn($config), $config, $options);
33+
34+
$this->configureIsolationLevel($connection, $config);
35+
36+
return $connection;
37+
}
38+
39+
/**
40+
* Set the connection transaction isolation level.
41+
*
42+
* https://learn.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql
43+
*
44+
* @param \PDO $connection
45+
* @param array $config
46+
* @return void
47+
*/
48+
protected function configureIsolationLevel($connection, array $config)
49+
{
50+
if (! isset($config['isolation_level'])) {
51+
return;
52+
}
53+
54+
$connection->prepare(
55+
"SET TRANSACTION ISOLATION LEVEL {$config['isolation_level']}"
56+
)->execute();
3357
}
3458

3559
/**

0 commit comments

Comments
 (0)