Skip to content

Commit

Permalink
Fixed encoding of empty ArrayExpression for PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Mar 3, 2018
1 parent d5d4b8b commit 5fa25b3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Yii Framework 2 Change Log
- Bug #15822: Fixed `yii\base\Component::off()` not to throw an exception when handler does not exist (silverfire)
- Bug #15817: Fixed support of deprecated array format type casting in `yii\db\Command::bindValues()` (silverfire)
- Bug #15804: Fixed `null` values handling for PostgresSQL arrays (silverfire)
- Bug: Fixed encoding of empty `yii\db\ArrayExpression` for PostgreSQL (silverfire)


2.0.14.1 February 24, 2018
Expand Down
3 changes: 0 additions & 3 deletions framework/db/pgsql/ArrayExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public function build(ExpressionInterface $expression, array &$params = [])
}

$placeholders = $this->buildPlaceholders($expression, $params);
if (empty($placeholders)) {
return "'{}'";
}

return 'ARRAY[' . implode(', ', $placeholders) . ']' . $this->getTypehint($expression);
}
Expand Down
2 changes: 0 additions & 2 deletions framework/db/pgsql/ArrayParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ private function parseString($value, &$i)

if (!$isQuoted && $result === 'NULL') {
$result = null;
} elseif ($isQuoted && $result === '{}') {
$result = [];
}

return $result;
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/db/pgsql/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ public function arrayValuesProvider()
]],
'empty arrays values' => [[
'textarray2_col' => [
['', ''],
new ArrayExpression([[], []], 'text', 2),
[[], []],
new ArrayExpression([], 'text', 2),
],
]],
'arrays packed in classes' => [[
Expand Down
3 changes: 2 additions & 1 deletion tests/framework/db/pgsql/ArrayParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public function convertProvider()
['{1,2,}', ['1','2',null]],
['{{},,1}', [[], null, '1']],
['{"{\"key\":\"value\"}",NULL,"NULL","{}"}', ['{"key":"value"}', null, "NULL", '{}']],
['{boo,",",,test', ['boo', ',', null, 'test']],
['{boo,",",,test}', ['boo', ',', null, 'test']],
['{"string1","str\\\\in\\"g2","str,ing3"}', ['string1','str\\in"g2','str,ing3']],
['{{1,2,3},{4,5,6},{7,8,9}}', [['1','2','3'], ['4','5','6'], ['7','8','9']]],
['{utf8€,👍}', ['utf8€', '👍']],
['{"","","{}",{}}', ['', '', '{}', []]]
];
}

Expand Down
6 changes: 3 additions & 3 deletions tests/framework/db/pgsql/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ public function conditionProvider()

// array condition corner cases
[['@>', 'id', new ArrayExpression([1])], '"id" @> ARRAY[:qp0]', [':qp0' => 1]],
'scalar can not be converted to array #1' => [['@>', 'id', new ArrayExpression(1)], '"id" @> \'{}\'', []],
['scalar can not be converted to array #2' => ['@>', 'id', new ArrayExpression(false)], '"id" @> \'{}\'', []],
'scalar can not be converted to array #1' => [['@>', 'id', new ArrayExpression(1)], '"id" @> ARRAY[]', []],
['scalar can not be converted to array #2' => ['@>', 'id', new ArrayExpression(false)], '"id" @> ARRAY[]', []],
[['&&', 'price', new ArrayExpression([12, 14], 'float')], '"price" && ARRAY[:qp0, :qp1]::float[]', [':qp0' => 12, ':qp1' => 14]],
[['@>', 'id', new ArrayExpression([2, 3])], '"id" @> ARRAY[:qp0, :qp1]', [':qp0' => 2, ':qp1' => 3]],
'array of arrays' => [['@>', 'id', new ArrayExpression([[1,2], [3,4]], 'float', 2)], '"id" @> ARRAY[ARRAY[:qp0, :qp1]::float[], ARRAY[:qp2, :qp3]::float[]\\]::float[][]', [':qp0' => 1, ':qp1' => 2, ':qp2' => 3, ':qp3' => 4]],
[['@>', 'id', new ArrayExpression([])], '"id" @> \'{}\'', []],
[['@>', 'id', new ArrayExpression([])], '"id" @> ARRAY[]', []],
'array can contain nulls' => [['@>', 'id', new ArrayExpression([null])], '"id" @> ARRAY[:qp0]', [':qp0' => null]],
'traversable objects are supported' => [['@>', 'id', new ArrayExpression(new TraversableObject([1, 2, 3]))], '[[id]] @> ARRAY[:qp0, :qp1, :qp2]', [':qp0' => 1, ':qp1' => 2, ':qp2' => 3]],
[['@>', 'time', new ArrayExpression([new Expression('now()')])], '[[time]] @> ARRAY[now()]', []],
Expand Down

0 comments on commit 5fa25b3

Please sign in to comment.