Skip to content

Commit

Permalink
Merge pull request #12978 from themsaid/fix-for-postgres
Browse files Browse the repository at this point in the history
[5.2] Safe field names for Postgres JSON type
  • Loading branch information
taylorotwell committed Apr 2, 2016
2 parents cd304b7 + 0c2565e commit cb5423c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected function wrapJsonSelector($value)
{
$path = explode('->', $value);

$field = array_shift($path);
$field = $this->wrapValue(array_shift($path));

$wrappedPath = $this->wrapJsonPathAttributes($path);

Expand Down
6 changes: 3 additions & 3 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1219,15 +1219,15 @@ public function testPostgresWrappingJson()
{
$builder = $this->getPostgresBuilder();
$builder->select('items->price')->from('users')->where('items->price', '=', 1)->orderBy('items->price');
$this->assertEquals('select items->>\'price\' from "users" where items->>\'price\' = ? order by items->>\'price\' asc', $builder->toSql());
$this->assertEquals('select "items"->>\'price\' from "users" where "items"->>\'price\' = ? order by "items"->>\'price\' asc', $builder->toSql());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('items->price->in_usd', '=', 1);
$this->assertEquals('select * from "users" where items->\'price\'->>\'in_usd\' = ?', $builder->toSql());
$this->assertEquals('select * from "users" where "items"->\'price\'->>\'in_usd\' = ?', $builder->toSql());

$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->where('items->price->in_usd', '=', 1)->where('items->age', '=', 2);
$this->assertEquals('select * from "users" where items->\'price\'->>\'in_usd\' = ? and items->>\'age\' = ?', $builder->toSql());
$this->assertEquals('select * from "users" where "items"->\'price\'->>\'in_usd\' = ? and "items"->>\'age\' = ?', $builder->toSql());
}

public function testSQLiteOrderBy()
Expand Down

0 comments on commit cb5423c

Please sign in to comment.