Skip to content

Commit

Permalink
Add try/catch for the substituteBindings (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Oct 18, 2024
1 parent b705c56 commit 6a79909
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,15 @@ private function getSqlQueryToDisplay(array $query): string
{
$sql = $query['query'];
if ($query['type'] === 'query' && $this->renderSqlWithParams && method_exists(DB::connection($query['connection'])->getQueryGrammar(), 'substituteBindingsIntoRawSql')) {
$sql = DB::connection($query['connection'])->getQueryGrammar()->substituteBindingsIntoRawSql($sql, $query['bindings'] ?? []);
} elseif ($query['type'] === 'query' && $this->renderSqlWithParams) {
try {
$sql = DB::connection($query['connection'])->getQueryGrammar()->substituteBindingsIntoRawSql($sql, $query['bindings'] ?? []);
return $this->getDataFormatter()->formatSql($sql);
} catch (\Throwable $e) {
// Continue using the old substitute
}
}

if ($query['type'] === 'query' && $this->renderSqlWithParams) {
$bindings = $this->getDataFormatter()->checkBindings($query['bindings']);
if (!empty($bindings)) {
$pdo = null;
Expand Down

0 comments on commit 6a79909

Please sign in to comment.