Skip to content

Commit

Permalink
Throw exception for unsupported lateral joins on MariaDB (laravel#50279)
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir authored Feb 27, 2024
1 parent 39561b1 commit a8f02b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.');
}
}
19 changes: 19 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a8f02b5

Please sign in to comment.