Skip to content

Commit f6958f1

Browse files
authored
Merge pull request #115 from andrex47/v4
V4
2 parents ae3949a + 0f2d5d2 commit f6958f1

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
@@ -519,4 +519,43 @@ public function getSchemaBuilder()
519519

520520
return $builder;
521521
}
522+
523+
/**
524+
* Run a SQL statement.
525+
*
526+
* @param string $query
527+
* @param array $bindings
528+
* @param \Closure $callback
529+
* @return mixed
530+
*
531+
* @throws \Illuminate\Database\QueryException
532+
*/
533+
protected function runQueryCallback($query, $bindings, Closure $callback)
534+
{
535+
try {
536+
$result = $callback($query, $bindings);
537+
538+
if ($result instanceof \PDOStatement) {
539+
$errorInfo = $result->errorInfo();
540+
if (isset($errorInfo[0]) && $errorInfo[0] !== '00000') {
541+
$finalErrorMessage = sprintf(
542+
'SQLSTATE[%s] [%d] %s',
543+
$errorInfo[0],
544+
(int)$errorInfo[1],
545+
trim(preg_replace(['/^\[\d+\]\s\(severity\s\d+\)\s/', '/\s+/'], ['', ' '], $errorInfo[2]))
546+
);
547+
throw new \PDOException($finalErrorMessage, (int)$errorInfo[1]);
548+
}
549+
}
550+
return $result;
551+
552+
} catch (Throwable $e) {
553+
throw new QueryException(
554+
$this->getName(),
555+
$query,
556+
$this->prepareBindings($bindings),
557+
$e
558+
);
559+
}
560+
}
522561
}

0 commit comments

Comments
 (0)