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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Bug #484: Fix building range-type column definitions (@Tigrov)
- Enh #489: Clarify return type of `phpTypecast()` methods for range columns (@Tigrov)
- New #492: Add `getBounds()` method to range values (@Tigrov)
- Bug #495: Add missed parameters for building expressions in `ArrayOverlapsBuilder` and `JsonOverlapsBuilder` classes (@Tigrov)

## 2.0.1 February 07, 2026

Expand Down
2 changes: 1 addition & 1 deletion src/Builder/ArrayOverlapsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public function build(ExpressionInterface $expression, array &$params = []): string
{
$column = $expression->column instanceof ExpressionInterface
? $this->queryBuilder->buildExpression($expression->column)
? $this->queryBuilder->buildExpression($expression->column, $params)
: $this->queryBuilder->getQuoter()->quoteColumnName($expression->column);
$values = $expression->values;

Expand All @@ -45,7 +45,7 @@

$values = $this->queryBuilder->buildExpression($values, $params);

if (preg_match('/::\w+\[]$/', $values, $matches) === 1) {

Check warning on line 48 in src/Builder/ArrayOverlapsBuilder.php

View workflow job for this annotation

GitHub Actions / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "PregMatchRemoveDollar": @@ @@ $values = new ArrayValue($values->value); } $values = $this->queryBuilder->buildExpression($values, $params); - if (preg_match('/::\w+\[]$/', $values, $matches) === 1) { + if (preg_match('/::\w+\[]/', $values, $matches) === 1) { $typeHint = $matches[0]; return "{$column}{$typeHint} && {$values}"; }
$typeHint = $matches[0];

return "$column$typeHint && $values";
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/JsonOverlapsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
public function build(ExpressionInterface $expression, array &$params = []): string
{
$column = $expression->column instanceof ExpressionInterface
? $this->queryBuilder->buildExpression($expression->column)
? $this->queryBuilder->buildExpression($expression->column, $params)
: $this->queryBuilder->getQuoter()->quoteColumnName($expression->column);
$values = $expression->values;

Expand Down
2 changes: 1 addition & 1 deletion src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected function isType(string $type): bool
protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnInterface $column): mixed
{
/** @var string $value */
$value = preg_replace("/::[^:']+$/", '$1', $defaultValue);
$value = preg_replace("/::[^:']+$/", '', $defaultValue);

if (str_starts_with($value, "B'") && $value[-1] === "'") {
return $column->phpTypecast(substr($value, 2, -1));
Expand Down
33 changes: 33 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,39 @@ public function testOverlapsConditionOperator(Closure|iterable|ExpressionInterfa
$this->assertSame($expectedCount, $count);
}

public function testArrayOverlapsWithExpressionColumnParams(): void
{
$db = $this->getSharedConnection();
$qb = $db->getQueryBuilder();
$params = [];

$sql = $qb->buildExpression(
new ArrayOverlaps(new Expression('array_remove(column, :empty)', [':empty' => null]), [1, 2, 3]),
$params,
);

$this->assertSame('array_remove(column, :empty)::int[] && ARRAY[1,2,3]::int[]', $sql);
$this->assertSame([':empty' => null], $params);
}

public function testJsonOverlapsWithExpressionColumnParams(): void
{
$db = $this->getSharedConnection();
$qb = $db->getQueryBuilder();
$params = [];

$sql = $qb->buildExpression(
new JsonOverlaps(new Expression('jsonb_path_query_array(column, :path)', [':path' => '$[*]']), [1, 2, 3]),
$params,
);

$this->assertSame(
'ARRAY(SELECT jsonb_array_elements_text(jsonb_path_query_array(column, :path)::jsonb))::int[] && ARRAY[1,2,3]::int[]',
$sql,
);
$this->assertSame([':path' => '$[*]'], $params);
}

#[DataProviderExternal(QueryBuilderProvider::class, 'buildColumnDefinition')]
public function testBuildColumnDefinition(string $expected, Closure|ColumnInterface|string $column): void
{
Expand Down
Loading