FIX Match multi-line JOIN statements (#10960)

This commit is contained in:
Guy Sartorelli 2023-09-26 10:30:55 +13:00 committed by GitHub
parent 157317d7ee
commit 55e42683f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -802,6 +802,6 @@ abstract class SQLConditionalExpression extends SQLExpression
*/ */
public static function getJoinRegex(): string public static function getJoinRegex(): string
{ {
return '/JOIN +.*? +(AS|ON|USING\(?) +/i'; return '/JOIN\s+.*?\s+(AS|ON|USING\(?)\s+/is';
} }
} }

View File

@ -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)));
}
}