Skip to content

Commit

Permalink
Replace || by concat on postgreSQLPlatform doctrine/orm#3938
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Bettini committed Mar 4, 2020
1 parent 5ffc845 commit 8f0236b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function getLocateExpression(string $string, string $substring, ?string $
return sprintf('POSITION(%s IN %s)', $substring, $string);
}

public function getConcatExpression(string ...$string) : string
{
return sprintf('CONCAT(%s)', implode(', ', $string));
}

protected function getDateArithmeticIntervalExpression(string $date, string $operator, string $interval, string $unit) : string
{
if ($unit === DateIntervalUnit::QUARTER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function testGeneratesSqlSnippets() : void
{
self::assertEquals('SIMILAR TO', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct');
self::assertEquals('"', $this->platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
self::assertEquals('column1 || column2 || column3', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
self::assertEquals('CONCAT(column1, column2, column3)', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
self::assertEquals('SUBSTRING(column FROM 5)', $this->platform->getSubstringExpression('column', '5'), 'Substring expression without length is not correct');
self::assertEquals('SUBSTRING(column FROM 1 FOR 5)', $this->platform->getSubstringExpression('column', '1', '5'), 'Substring expression with length is not correct');
}
Expand Down

0 comments on commit 8f0236b

Please sign in to comment.