Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,12 @@ public function buildCondition(array $condition, array &$values): string
}
} else {
if ($value instanceof ExpressionInterface) {
$sql[] = $this->buildExpression($value, $values);
$stmt = $this->buildExpression($value, $values);
if (is_int($expression)) {
$sql[] = $stmt;
} else {
$sql[] = str_replace('?', $stmt, $expression);
}
} elseif ($value instanceof Select) {
$stmt = '(' . $this->assembleSelect($value, $values)[0] . ')';
if (is_int($expression)) {
Expand Down
11 changes: 11 additions & 0 deletions tests/FilterProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ipl\Tests\Sql;

use ipl\Sql\Compat\FilterProcessor;
use ipl\Sql\Expression;
use ipl\Sql\Filter\Exists;
use ipl\Sql\Filter\In;
use ipl\Sql\Filter\NotExists;
Expand Down Expand Up @@ -116,4 +117,14 @@ public function testNotExistsToSql()
FilterProcessor::assemblePredicate(new NotExists($select))
);
}

public function testFilterWithExpressionToSql(): void
{
$expression = new Expression('NOW()');

$this->assertSame(
['foo = ?' => $expression],
FilterProcessor::assemblePredicate(Filter::equal('foo', $expression))
);
}
}
5 changes: 5 additions & 0 deletions tests/WhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public function testWhereWithExpression()
$this->query->where($expression);

$this->assertSql('WHERE c2 = ?', $this->query, [1]);

$expression = new Expression('NOW()');
$this->query->where(['c3 = ?' => $expression]);

$this->assertSql('WHERE (c2 = ?) AND (c3 = NOW())', $this->query, [1]);
}

public function testWhereWithSelect()
Expand Down
Loading