Skip to content

Commit 4a12820

Browse files
authored
Merge pull request #112 from uepg/101-fix-silent-exceptions
101 fix silent exceptions
2 parents 7099bb9 + 24ab8cb commit 4a12820

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Database/Connection.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,4 +530,43 @@ public function getSchemaBuilder()
530530

531531
return $builder;
532532
}
533+
534+
/**
535+
* Run a SQL statement.
536+
*
537+
* @param string $query
538+
* @param array $bindings
539+
* @param \Closure $callback
540+
* @return mixed
541+
*
542+
* @throws \Illuminate\Database\QueryException
543+
*/
544+
protected function runQueryCallback($query, $bindings, Closure $callback)
545+
{
546+
try {
547+
$result = $callback($query, $bindings);
548+
549+
if ($result instanceof \PDOStatement) {
550+
$errorInfo = $result->errorInfo();
551+
if (isset($errorInfo[0]) && $errorInfo[0] !== '00000') {
552+
$finalErrorMessage = sprintf(
553+
'SQLSTATE[%s] [%d] %s',
554+
$errorInfo[0],
555+
(int)$errorInfo[1],
556+
trim(preg_replace(['/^\[\d+\]\s\(severity\s\d+\)\s/', '/\s+/'], ['', ' '], $errorInfo[2]))
557+
);
558+
throw new \PDOException($finalErrorMessage, (int)$errorInfo[1]);
559+
}
560+
}
561+
return $result;
562+
563+
} catch (Throwable $e) {
564+
throw new QueryException(
565+
$this->getName(),
566+
$query,
567+
$this->prepareBindings($bindings),
568+
$e
569+
);
570+
}
571+
}
533572
}

0 commit comments

Comments
 (0)