Skip to content

Commit

Permalink
FIX Match multi-line JOIN statements
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Sep 25, 2023
1 parent 157317d commit 142035f
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 142035f

Please sign in to comment.