Commit 7ac8d9ac authored by Crell's avatar Crell
Browse files

Add a database wrapping exception for PDOExceptions to carry additional debug information.

parent acf9151a
...@@ -524,15 +524,15 @@ public function query($query, array $args = array(), $options = array()) { ...@@ -524,15 +524,15 @@ public function query($query, array $args = array(), $options = array()) {
} }
catch (PDOException $e) { catch (PDOException $e) {
if ($options['throw_exception']) { if ($options['throw_exception']) {
// Add additional debug information. // Wrap the exception in another exception. Its message is the extra
if ($query instanceof DatabaseStatementInterface) { // database debug information. We have to do it this way because PHP
$e->query_string = $stmt->getQueryString(); // does not allow us to override Exception::getMessage().
}
else { $query_string = ($query instanceof DatabaseStatementInterface) ? $stmt->getQueryString() : $query;
$e->query_string = $query; $message = $e->getMessage() . ": " . $query_string . "; " . print_r($args, TRUE);
} $exception = new DatabaseExceptionWrapper($message, 0, $e);
$e->args = $args;
throw $e; throw $exception;
} }
return NULL; return NULL;
} }
......
<?php
/**
* @file
* Definition of Drupal\Core\Database\DatabaseExceptionWrapper
*/
namespace Drupal\Core\Database;
use RuntimeException;
/**
* This wrapper class serves only to provide additional debug information.
*
* This class will always wrap a PDOException.
*/
class DatabaseExceptionWrapper extends RuntimeException implements DatabaseException {
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment