Skip to content

Commit

Permalink
[5.4] Execute queries with lock only in write database (#17386)
Browse files Browse the repository at this point in the history
* Add regression test as a bug proof.

* Fix execution queries with locks on the read PDO instance.
  • Loading branch information
SebastianBerc authored and taylorotwell committed Jan 18, 2017
1 parent 7ece167 commit ed1550f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1606,14 +1606,14 @@ public function unionAll($query)
/**
* Lock the selected rows in the table.
*
* @param bool $value
* @param string|bool $value
* @return $this
*/
public function lock($value = true)
{
$this->lock = $value;

if ($this->lock) {
if (! is_null($this->lock)) {
$this->useWritePdo();
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,11 @@ public function testSelectWithLockUsesWritePdo()
$builder->getConnection()->shouldReceive('select')->once()
->with(m::any(), m::any(), false);
$builder->select('*')->from('foo')->where('bar', '=', 'baz')->lock()->get();

$builder = $this->getMySqlBuilderWithProcessor();
$builder->getConnection()->shouldReceive('select')->once()
->with(m::any(), m::any(), false);
$builder->select('*')->from('foo')->where('bar', '=', 'baz')->lock(false)->get();
}

public function testBindingOrder()
Expand Down

0 comments on commit ed1550f

Please sign in to comment.