diff --git a/src/Watchers/QueryWatcher.php b/src/Watchers/QueryWatcher.php index 534c12bb3..28f38c908 100644 --- a/src/Watchers/QueryWatcher.php +++ b/src/Watchers/QueryWatcher.php @@ -103,7 +103,10 @@ public function replaceBindings($event) $binding = $this->quoteStringBinding($event, $binding); } - $sql = preg_replace($regex, $binding, $sql, 1); + // To support named binding with multiple occurrences + $limit = is_numeric($key) ? 1 : -1; + + $sql = preg_replace($regex, $binding, $sql, $limit); } return $sql; diff --git a/tests/Watchers/QueryWatcherTest.php b/tests/Watchers/QueryWatcherTest.php index f60e4c4ee..a4c0153a3 100644 --- a/tests/Watchers/QueryWatcherTest.php +++ b/tests/Watchers/QueryWatcherTest.php @@ -80,7 +80,7 @@ public function test_query_watcher_can_prepare_bindings() public function test_query_watcher_can_prepare_named_bindings() { $this->app->get('db')->statement(<<<'SQL' -update "telescope_entries" set "content" = :content, "should_display_on_index" = :index_new where "type" = :type and "should_display_on_index" = :index_old and "family_hash" is null and "sequence" > :sequence and "created_at" < :created_at +update "telescope_entries" set "content" = :content, "should_display_on_index" = :index_new where "type" = :type and "should_display_on_index" = :index_old and "family_hash" is null and "sequence" > :sequence and "created_at" < :created_at and "created_at" <> :created_at SQL , [ 'sequence' => 100, @@ -95,7 +95,7 @@ public function test_query_watcher_can_prepare_named_bindings() $this->assertSame(EntryType::QUERY, $entry->type); $this->assertSame(<<<'SQL' -update "telescope_entries" set "content" = null, "should_display_on_index" = 0 where "type" = 'query' and "should_display_on_index" = 1 and "family_hash" is null and "sequence" > 100 and "created_at" < '2019-01-01 00:00:00' +update "telescope_entries" set "content" = null, "should_display_on_index" = 0 where "type" = 'query' and "should_display_on_index" = 1 and "family_hash" is null and "sequence" > 100 and "created_at" < '2019-01-01 00:00:00' and "created_at" <> '2019-01-01 00:00:00' SQL , $entry->content['sql']);