Skip to content

Commit

Permalink
FIX Match multi-line JOIN statements (#10960)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Sep 25, 2023
1 parent 157317d commit 55e4268
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ORM/Queries/SQLConditionalExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,6 @@ public function toUpdate()
*/
public static function getJoinRegex(): string
{
return '/JOIN +.*? +(AS|ON|USING\(?) +/i';
return '/JOIN\s+.*?\s+(AS|ON|USING\(?)\s+/is';
}
}
27 changes: 27 additions & 0 deletions tests/php/ORM/DBQueryBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace SilverStripe\ORM\Tests;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Connect\DBQueryBuilder;
use SilverStripe\ORM\Queries\SQLSelect;

class DBQueryBuilderTest extends SapphireTest
{
protected $usesDatabase = false;

public function testMultilineJoin()
{
$join = <<<JOIN
INNER JOIN
(SELECT DISTINCT "SiteTreeLink"."ClassName", "SiteTreeLink"."LastEdited", "SiteTreeLink"."Created", "SiteTreeLink"."LinkedID",
"SiteTreeLink"."ParentID", "SiteTreeLink"."ParentClass", "SiteTreeLink"."ID" FROM "SiteTreeLink")
AS "SiteTreeLink" ON "SiteTreeLink"."LinkedID" = "SiteTree"."ID"
JOIN;
$select = new SQLSelect('*', ['SomeTable', $join]);
$builder = new DBQueryBuilder();

$params = [];
$this->assertSame('FROM SomeTable ' . $join, trim($builder->buildFromFragment($select, $params)));
}
}

0 comments on commit 55e4268

Please sign in to comment.