From 32ee7417755b8eb29afa34be571a8f44cc0413e7 Mon Sep 17 00:00:00 2001 From: osindex Date: Fri, 9 Aug 2019 16:59:28 +0800 Subject: [PATCH 1/2] avoid vsprintf() error vsprintf(): Too few arguments when use \DB::update(DB::raw($q) --- src/ServiceProvider.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 7931e3f..917099f 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -32,8 +32,12 @@ public function boot() $bindings = $query->connection->prepareBindings($query->bindings); $pdo = $query->connection->getPdo(); - $realSql = vsprintf($sqlWithPlaceholders, array_map([$pdo, 'quote'], $bindings)); - $duration = $this->formatDuration($query->time / 1000); + if (count($bindings)) { + $pdo = $query->connection->getPdo(); + $realSql = vsprintf($sqlWithPlaceholders, array_map([$pdo, 'quote'], $bindings)); + } else { + $realSql = $sqlWithPlaceholders; + } Log::debug(sprintf('[%s] %s | %s: %s', $duration, $realSql, request()->method(), request()->getRequestUri())); }); From 5540e59ea383ced098e35b086afd06064f4ff483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Wed, 4 Mar 2020 18:21:35 +0800 Subject: [PATCH 2/2] Update ServiceProvider.php --- src/ServiceProvider.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 917099f..6658e02 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -32,11 +32,10 @@ public function boot() $bindings = $query->connection->prepareBindings($query->bindings); $pdo = $query->connection->getPdo(); - if (count($bindings)) { - $pdo = $query->connection->getPdo(); - $realSql = vsprintf($sqlWithPlaceholders, array_map([$pdo, 'quote'], $bindings)); - } else { - $realSql = $sqlWithPlaceholders; + $realSql = $sqlWithPlaceholders; + + if (count($bindings) > 0) { + $realSql = vsprintf($sqlWithPlaceholders, array_map([$pdo, 'quote'], $bindings)); } Log::debug(sprintf('[%s] %s | %s: %s', $duration, $realSql, request()->method(), request()->getRequestUri()));