diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index f95bccff0be..fc1f2776b66 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -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 diff --git a/framework/db/pgsql/ArrayExpressionBuilder.php b/framework/db/pgsql/ArrayExpressionBuilder.php index 577aacc4ef0..6eb86eb1f61 100644 --- a/framework/db/pgsql/ArrayExpressionBuilder.php +++ b/framework/db/pgsql/ArrayExpressionBuilder.php @@ -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); } diff --git a/framework/db/pgsql/ArrayParser.php b/framework/db/pgsql/ArrayParser.php index fc66789d40e..8ce08b24f5a 100644 --- a/framework/db/pgsql/ArrayParser.php +++ b/framework/db/pgsql/ArrayParser.php @@ -102,8 +102,6 @@ private function parseString($value, &$i) if (!$isQuoted && $result === 'NULL') { $result = null; - } elseif ($isQuoted && $result === '{}') { - $result = []; } return $result; diff --git a/tests/framework/db/pgsql/ActiveRecordTest.php b/tests/framework/db/pgsql/ActiveRecordTest.php index 6bce5d08591..b467185b0e2 100644 --- a/tests/framework/db/pgsql/ActiveRecordTest.php +++ b/tests/framework/db/pgsql/ActiveRecordTest.php @@ -245,8 +245,8 @@ public function arrayValuesProvider() ]], 'empty arrays values' => [[ 'textarray2_col' => [ - ['', ''], - new ArrayExpression([[], []], 'text', 2), + [[], []], + new ArrayExpression([], 'text', 2), ], ]], 'arrays packed in classes' => [[ diff --git a/tests/framework/db/pgsql/ArrayParserTest.php b/tests/framework/db/pgsql/ArrayParserTest.php index f053c862e34..1962676180a 100644 --- a/tests/framework/db/pgsql/ArrayParserTest.php +++ b/tests/framework/db/pgsql/ArrayParserTest.php @@ -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€', '👍']], + ['{"","","{}",{}}', ['', '', '{}', []]] ]; } diff --git a/tests/framework/db/pgsql/QueryBuilderTest.php b/tests/framework/db/pgsql/QueryBuilderTest.php index 09d6f925d84..89d8c9dad8e 100644 --- a/tests/framework/db/pgsql/QueryBuilderTest.php +++ b/tests/framework/db/pgsql/QueryBuilderTest.php @@ -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()]', []],