Skip to content

Commit

Permalink
Merge pull request #4939 from morozov/issues/3346
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Oct 31, 2021
2 parents ea1d9d1 + 317c056 commit c52fe04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Platforms/SQLServer2012Platform.php
Expand Up @@ -1146,9 +1146,7 @@ public function getTrimExpression($str, $mode = TrimMode::UNSPECIFIED, $char = f
*/
public function getConcatExpression()
{
$args = func_get_args();

return '(' . implode(' + ', $args) . ')';
return sprintf('CONCAT(%s)', implode(', ', func_get_args()));
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/Functional/Platform/ConcatExpressionTest.php
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Platform;

use Doctrine\DBAL\Tests\FunctionalTestCase;

final class ConcatExpressionTest extends FunctionalTestCase
{
/**
* @param list<string> $arguments
*
* @dataProvider expressionProvider
*/
public function testConcatExpression(array $arguments, string $expected): void
{
$platform = $this->connection->getDatabasePlatform();
$query = $platform->getDummySelectSQL($platform->getConcatExpression(...$arguments));

self::assertEquals($expected, $this->connection->fetchOne($query));
}

/**
* @return iterable<string,array{list<string>,string}>
*/
public static function expressionProvider(): iterable
{
yield 'strings' => [["'foo'", "'bar'"], 'foobar'];
yield 'numbers and a hyphen' => [['2010', "'-'", '2019'], '2010-2019'];
}
}

0 comments on commit c52fe04

Please sign in to comment.