Skip to content

Commit

Permalink
Fixed exception that is thrown when combining the sqlite CONCAT_WS ex…
Browse files Browse the repository at this point in the history
…tension with a LimitSubqueryOutputWalker
  • Loading branch information
Adam van Reijswoud authored and stevelacey committed Dec 5, 2019
1 parent fccc6a9 commit af72c4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Query/Sqlite/ConcatWs.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function parse(\Doctrine\ORM\Query\Parser $parser)

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
$separator = array_shift($this->values)->simpleArithmeticExpression->value;
$separator = $this->values[0]->simpleArithmeticExpression->value;

// Create an array to hold the query elements.
$queryBuilder = ['('];

// Iterate over the captured expressions and add them to the query.
for ($i = 0; $i < count($this->values); $i++) {
if ($i > 0) {
for ($i = 1; $i < count($this->values); $i++) {
if ($i > 1) {
$queryBuilder[] = " || '${separator}' || ";
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Query/Sqlite/ConcatWsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace DoctrineExtensions\Tests\Query\Sqlite;

use DoctrineExtensions\Tests\Query\SqliteTestCase;

class ConcatWsTest extends SqliteTestCase
{
public function testConcatWs()
{
$dql = "SELECT CONCAT_WS(',', p.id, p.name) FROM DoctrineExtensions\\Tests\\Entities\\Product p";

$this->assertEquals(
"SELECT (IFNULL(p0_.id, '') || ',' || IFNULL(p0_.name, '')) AS {$this->columnAlias} FROM Product p0_",
$this->entityManager->createQuery($dql)->getSql()
);
}
}

0 comments on commit af72c4a

Please sign in to comment.