From 628f290a9e077bc34140cc10ce0e30f7ffa7106c Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 7 Sep 2019 08:28:24 +0200 Subject: [PATCH 1/3] Check for null values in query bindings --- src/Watchers/QueryWatcher.php | 4 +++- tests/Watchers/QueryWatcherTest.php | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Watchers/QueryWatcher.php b/src/Watchers/QueryWatcher.php index 2cba2dab6..e795bf7f7 100644 --- a/src/Watchers/QueryWatcher.php +++ b/src/Watchers/QueryWatcher.php @@ -96,7 +96,9 @@ public function replaceBindings($event) ? "/\?(?=(?:[^'\\\']*'[^'\\\']*')*[^'\\\']*$)/" : "/:{$key}(?=(?:[^'\\\']*'[^'\\\']*')*[^'\\\']*$)/"; - if (! is_int($binding) && ! is_float($binding)) { + if ($binding === null) { + $binding = 'null'; + } elseif (! is_int($binding) && ! is_float($binding)) { $binding = $event->connection->getPdo()->quote($binding); } diff --git a/tests/Watchers/QueryWatcherTest.php b/tests/Watchers/QueryWatcherTest.php index b2f4c4e25..65fa1dfe5 100644 --- a/tests/Watchers/QueryWatcherTest.php +++ b/tests/Watchers/QueryWatcherTest.php @@ -60,12 +60,19 @@ public function test_query_watcher_can_prepare_bindings() ->where('should_display_on_index', true) ->whereNull('family_hash') ->where('created_at', '<', Carbon::parse('2019-01-01')) - ->count(); + ->update([ + 'content' => null, + 'should_display_on_index' => false, + ]); $entry = $this->loadTelescopeEntries()->first(); $this->assertSame(EntryType::QUERY, $entry->type); - $this->assertSame('select count(*) as aggregate from "telescope_entries" where "type" = \'query\' and "should_display_on_index" = 1 and "family_hash" is null and "created_at" < \'2019-01-01 00:00:00\'', $entry->content['sql']); + $this->assertSame(<<content['sql']); + $this->assertSame('testbench', $entry->content['connection']); } } From d013064f70d43242b8b2bb8294959743b5662e5d Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 7 Sep 2019 08:33:32 +0200 Subject: [PATCH 2/3] CS fix --- tests/Watchers/QueryWatcherTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Watchers/QueryWatcherTest.php b/tests/Watchers/QueryWatcherTest.php index 65fa1dfe5..9ecb30391 100644 --- a/tests/Watchers/QueryWatcherTest.php +++ b/tests/Watchers/QueryWatcherTest.php @@ -68,7 +68,7 @@ public function test_query_watcher_can_prepare_bindings() $entry = $this->loadTelescopeEntries()->first(); $this->assertSame(EntryType::QUERY, $entry->type); - $this->assertSame(<<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 "created_at" < '2019-01-01 00:00:00' SQL , $entry->content['sql']); From 4e43ad98e825162c61b1cffc010235316f87a644 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 7 Sep 2019 11:31:45 +0200 Subject: [PATCH 3/3] Update tests for named parameters/integers --- tests/Watchers/QueryWatcherTest.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/Watchers/QueryWatcherTest.php b/tests/Watchers/QueryWatcherTest.php index 9ecb30391..395d7a1de 100644 --- a/tests/Watchers/QueryWatcherTest.php +++ b/tests/Watchers/QueryWatcherTest.php @@ -59,6 +59,7 @@ public function test_query_watcher_can_prepare_bindings() ->where('type', 'query') ->where('should_display_on_index', true) ->whereNull('family_hash') + ->where('sequence', '>', 100) ->where('created_at', '<', Carbon::parse('2019-01-01')) ->update([ 'content' => null, @@ -69,7 +70,32 @@ public function test_query_watcher_can_prepare_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 "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' +SQL + , $entry->content['sql']); + + $this->assertSame('testbench', $entry->content['connection']); + } + + 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 +SQL + , [ + 'sequence' => 100, + 'index_old' => 1, + 'type' => 'query', + 'created_at' => Carbon::parse('2019-01-01'), + 'index_new' => 0, + 'content' => null, + ]); + + $entry = $this->loadTelescopeEntries()->first(); + + $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' SQL , $entry->content['sql']);