Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Support named query bindings with multiple occurrences #1358

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Watchers/QueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/Watchers/QueryWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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']);

Expand Down