From 4a8886b5c5d14a8523ab51b5733bd0b450277b6f Mon Sep 17 00:00:00 2001 From: Michael WIkberg <130439907+mwikberg-virta@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:04:52 +0200 Subject: [PATCH 1/4] Fix transaction isolation level in MySqlConnector.php --- src/Illuminate/Database/Connectors/MySqlConnector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Connectors/MySqlConnector.php b/src/Illuminate/Database/Connectors/MySqlConnector.php index 51b6a79ca135..bb1adc05ecc0 100755 --- a/src/Illuminate/Database/Connectors/MySqlConnector.php +++ b/src/Illuminate/Database/Connectors/MySqlConnector.php @@ -96,7 +96,7 @@ protected function configureConnection(PDO $connection, array $config) $statements = []; if (isset($config['isolation_level'])) { - $statements[] = sprintf('SESSION TRANSACTION ISOLATION LEVEL %s', $config['isolation_level']); + $connection->exec(sprintf('SET SESSION TRANSACTION ISOLATION LEVEL %s;', $config['isolation_level'])); } if (isset($config['charset'])) { From 8177008ed7f242b606d389bb023ac7e2369d682c Mon Sep 17 00:00:00 2001 From: Michael WIkberg <130439907+mwikberg-virta@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:09:26 +0200 Subject: [PATCH 2/4] Update DatabaseConnectorTest.php --- tests/Database/DatabaseConnectorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Database/DatabaseConnectorTest.php b/tests/Database/DatabaseConnectorTest.php index 4774b6caff73..05ad80bdfded 100755 --- a/tests/Database/DatabaseConnectorTest.php +++ b/tests/Database/DatabaseConnectorTest.php @@ -62,7 +62,8 @@ public function testMySqlConnectCallsCreateConnectionWithIsolationLevel() $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']); $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection); $connection->shouldReceive('exec')->once()->with('use `bar`;')->andReturn(true); - $connection->shouldReceive('exec')->once()->with("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, NAMES 'utf8' COLLATE 'utf8_unicode_ci';")->andReturn(true); + $connection->shouldReceive('exec')->once()->with("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;")->andReturn(true); + $connection->shouldReceive('exec')->once()->with("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';")->andReturn(true); $result = $connector->connect($config); $this->assertSame($result, $connection); From 3ed5e5069b0e3ad4ef4c78f290f54677a74d12fc Mon Sep 17 00:00:00 2001 From: Michael Wikberg Date: Thu, 21 Mar 2024 09:35:54 +0200 Subject: [PATCH 3/4] Style fix --- tests/Database/DatabaseConnectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Database/DatabaseConnectorTest.php b/tests/Database/DatabaseConnectorTest.php index 05ad80bdfded..ca45cfa36465 100755 --- a/tests/Database/DatabaseConnectorTest.php +++ b/tests/Database/DatabaseConnectorTest.php @@ -62,7 +62,7 @@ public function testMySqlConnectCallsCreateConnectionWithIsolationLevel() $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']); $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection); $connection->shouldReceive('exec')->once()->with('use `bar`;')->andReturn(true); - $connection->shouldReceive('exec')->once()->with("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;")->andReturn(true); + $connection->shouldReceive('exec')->once()->with('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;')->andReturn(true); $connection->shouldReceive('exec')->once()->with("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';")->andReturn(true); $result = $connector->connect($config); From f29a5d92147017b02466d5f1931a4620fbb5aa0c Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 21 Mar 2024 08:15:26 +0000 Subject: [PATCH 4/4] Code style fix --- src/Illuminate/Database/Connectors/MySqlConnector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Connectors/MySqlConnector.php b/src/Illuminate/Database/Connectors/MySqlConnector.php index bb1adc05ecc0..0ecaf8bf4551 100755 --- a/src/Illuminate/Database/Connectors/MySqlConnector.php +++ b/src/Illuminate/Database/Connectors/MySqlConnector.php @@ -93,12 +93,12 @@ protected function getHostDsn(array $config) */ protected function configureConnection(PDO $connection, array $config) { - $statements = []; - if (isset($config['isolation_level'])) { $connection->exec(sprintf('SET SESSION TRANSACTION ISOLATION LEVEL %s;', $config['isolation_level'])); } + $statements = []; + if (isset($config['charset'])) { if (isset($config['collation'])) { $statements[] = sprintf("NAMES '%s' COLLATE '%s'", $config['charset'], $config['collation']);