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()) {
}
catch (PDOException $e) {
if ($options['throw_exception']) {
// Add additional debug information.
if ($query instanceof DatabaseStatementInterface) {
$e->query_string = $stmt->getQueryString();
}
else {
$e->query_string = $query;
}
$e->args = $args;
throw $e;
// Wrap the exception in another exception. Its message is the extra
// database debug information. We have to do it this way because PHP
// does not allow us to override Exception::getMessage().
$query_string = ($query instanceof DatabaseStatementInterface) ? $stmt->getQueryString() : $query;
$message = $e->getMessage() . ": " . $query_string . "; " . print_r($args, TRUE);
$exception = new DatabaseExceptionWrapper($message, 0, $e);
throw $exception;
}
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