Fixed encoding of empty ArrayExpression for PostgreSQL

This commit is contained in:
SilverFire - Dmitry Naumenko
2018-03-03 20:43:37 +02:00
parent d5d4b8b0f5
commit 5fa25b331d
6 changed files with 8 additions and 11 deletions

View File

@@ -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

View File

@@ -42,9 +42,6 @@ class ArrayExpressionBuilder implements ExpressionBuilderInterface
}
$placeholders = $this->buildPlaceholders($expression, $params);
if (empty($placeholders)) {
return "'{}'";
}
return 'ARRAY[' . implode(', ', $placeholders) . ']' . $this->getTypehint($expression);
}

View File

@@ -102,8 +102,6 @@ class ArrayParser
if (!$isQuoted && $result === 'NULL') {
$result = null;
} elseif ($isQuoted && $result === '{}') {
$result = [];
}
return $result;

View File

@@ -245,8 +245,8 @@ class ActiveRecordTest extends \yiiunit\framework\db\ActiveRecordTest
]],
'empty arrays values' => [[
'textarray2_col' => [
['', ''],
new ArrayExpression([[], []], 'text', 2),
[[], []],
new ArrayExpression([], 'text', 2),
],
]],
'arrays packed in classes' => [[

View File

@@ -28,10 +28,11 @@ class ArrayParserTest extends TestCase
['{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€', '👍']],
['{"","","{}",{}}', ['', '', '{}', []]]
];
}

View File

@@ -93,12 +93,12 @@ class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest
// 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()]', []],