From a8f02b5056de535470ac93f9dd12771e755dcb98 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Tue, 27 Feb 2024 13:12:24 +0100 Subject: [PATCH] Throw exception for unsupported lateral joins on MariaDB (#50279) --- .../Query/Grammars/MariaDbGrammar.php | 16 ++++++++++++++++ tests/Database/DatabaseQueryBuilderTest.php | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php b/src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php index 37d2cc015431..f165ada3e09c 100755 --- a/src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php @@ -3,6 +3,8 @@ namespace Illuminate\Database\Query\Grammars; use Illuminate\Database\Query\Builder; +use Illuminate\Database\Query\JoinLateralClause; +use RuntimeException; class MariaDbGrammar extends MySqlGrammar { @@ -16,4 +18,18 @@ public function useLegacyGroupLimit(Builder $query) { return false; } + + /** + * Compile a "lateral join" clause. + * + * @param \Illuminate\Database\Query\JoinLateralClause $join + * @param string $expression + * @return string + * + * @throws \RuntimeException + */ + public function compileJoinLateral(JoinLateralClause $join, string $expression): string + { + throw new RuntimeException('This database engine does not support lateral joins.'); + } } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 7d2cd301a9a6..9ac232e78531 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -11,6 +11,7 @@ use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\Expression as Raw; use Illuminate\Database\Query\Grammars\Grammar; +use Illuminate\Database\Query\Grammars\MariaDbGrammar; use Illuminate\Database\Query\Grammars\MySqlGrammar; use Illuminate\Database\Query\Grammars\PostgresGrammar; use Illuminate\Database\Query\Grammars\SQLiteGrammar; @@ -2572,6 +2573,16 @@ public function testJoinLateral() $builder->from('users')->joinLateral(['foo'], 'sub'); } + public function testJoinLateralMariaDb() + { + $this->expectException(RuntimeException::class); + $builder = $this->getMariaDbBuilder(); + $builder->getConnection()->shouldReceive('getDatabaseName'); + $builder->from('users')->joinLateral(function ($q) { + $q->from('contacts')->whereColumn('contracts.user_id', 'users.id'); + }, 'sub')->toSql(); + } + public function testJoinLateralSQLite() { $this->expectException(RuntimeException::class); @@ -5992,6 +6003,14 @@ protected function getMySqlBuilder() return new Builder(m::mock(ConnectionInterface::class), $grammar, $processor); } + protected function getMariaDbBuilder() + { + $grammar = new MariaDbGrammar; + $processor = m::mock(Processor::class); + + return new Builder(m::mock(ConnectionInterface::class), $grammar, $processor); + } + protected function getSQLiteBuilder() { $grammar = new SQLiteGrammar;