Skip to content

Commit

Permalink
Fix issue #4282, again
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Oct 8, 2020
1 parent c361b36 commit 8e28160
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,9 @@ public function andWhere($where)
$where = $this->getQueryPart('where');

if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_AND) {
$where = $where->with(...$args);
if ($args) {
$where = $where->with(...$args);
}
} else {
array_unshift($args, $where);
$where = CompositeExpression::and(...$args);
Expand Down Expand Up @@ -868,7 +870,9 @@ public function orWhere($where)
$where = $this->getQueryPart('where');

if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_OR) {
$where = $where->with(...$args);
if ($args) {
$where = $where->with(...$args);
}
} else {
array_unshift($args, $where);
$where = CompositeExpression::or(...$args);
Expand Down
26 changes: 26 additions & 0 deletions tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,19 @@ public function testJoinWithNonUniqueAliasThrowsException(): void
$qb->getSQL();
}

public function testWhereExpressionAndWhereEmptyString(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo')
->where('a = b');

$qb->andWhere('');

self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL());
}

public function testAndWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);
Expand All @@ -975,6 +988,19 @@ public function testAndWhereEmptyStringStartingWithNonEmptyExpression(): void
self::assertSame('SELECT id FROM foo WHERE (a = b) AND (c = d)', $qb->getSQL());
}

public function testWhereExpressionOrWhereEmptyString(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('id')
->from('foo')
->orWhere('a = b');

$qb->orWhere('');

self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL());
}

public function testOrWhereEmptyStringStartingWithEmptyExpression(): void
{
$qb = new QueryBuilder($this->conn);
Expand Down

0 comments on commit 8e28160

Please sign in to comment.