Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Ensure table aliases longer than max characters are safely re-wri…
…tten
- Loading branch information
Damian Mooyman
committed
May 25, 2017
1 parent
512f10d
commit e941f0b
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ language: php | |
sudo: false | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
|
||
env: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\ORM\Queries\SQLSelect; | ||
use SilverStripe\PostgreSQL\PostgreSQLQueryBuilder; | ||
|
||
class PostgreSQLQueryBuilderTest extends SapphireTest | ||
{ | ||
public function testLongAliases() | ||
{ | ||
$query = new SQLSelect(); | ||
$longstring = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
$alias2 = $longstring . $longstring; | ||
$query->selectField('*'); | ||
$query->addFrom('"Base"'); | ||
$query->addLeftJoin( | ||
'Joined', | ||
"\"Base\".\"ID\" = \"{$alias2}\".\"ID\"", | ||
$alias2 | ||
); | ||
$query->addWhere([ | ||
"\"{$alias2}\".\"Title\" = ?" => 'Value', | ||
]); | ||
|
||
$identifier = "c4afb43_hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
$this->assertEquals(PostgreSQLQueryBuilder::MAX_TABLE, strlen($identifier)); | ||
|
||
$expected = <<<SQL | ||
SELECT * | ||
FROM "Base" LEFT JOIN "Joined" AS "c4afb43_hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
ON "Base"."ID" = "c4afb43_hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"."ID" | ||
WHERE ("c4afb43_hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"."Title" = ?) | ||
SQL; | ||
$builder = new PostgreSQLQueryBuilder(); | ||
$sql = $builder->buildSQL($query, $params); | ||
|
||
$this->assertSQLEquals($expected, $sql); | ||
$this->assertEquals(['Value'], $params); | ||
} | ||
} |