From ed1550f633e8e1efd14985f60b6b5cee4fced651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ber=C4=87?= Date: Wed, 18 Jan 2017 20:02:03 +0100 Subject: [PATCH] [5.4] Execute queries with lock only in write database (#17386) * Add regression test as a bug proof. * Fix execution queries with locks on the read PDO instance. --- src/Illuminate/Database/Query/Builder.php | 4 ++-- tests/Database/DatabaseQueryBuilderTest.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index cb8b922b5492..e1911ae83028 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -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(); } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 769c71252b44..833ce5094c3a 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -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()