diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-06-01 16:47:06 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-06-01 16:47:06 +0000 |
commit | 00271e741f7d4825c76b1db21a7c55b250f209e9 (patch) | |
tree | 48a9ccf6abc25e43ba6a9049eae6245321b3ae1c /includes | |
parent | 8a0e218d32701d75c8ebb3c1d99b090f6f611f96 (diff) | |
download | brdo-00271e741f7d4825c76b1db21a7c55b250f209e9.tar.gz brdo-00271e741f7d4825c76b1db21a7c55b250f209e9.tar.bz2 |
- Patch #458176 by c960657: improved exception handling in database layer.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 9 | ||||
-rw-r--r-- | includes/database/database.inc | 8 | ||||
-rw-r--r-- | includes/database/pgsql/database.inc | 8 |
3 files changed, 17 insertions, 8 deletions
diff --git a/includes/common.inc b/includes/common.inc index 26282bf5b..e110e517a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -729,6 +729,8 @@ function _drupal_exception_handler($exception) { * @return An error in the format expected by _drupal_log_error(). */ function _drupal_decode_exception($exception) { + $message = $exception->getMessage(); + $backtrace = $exception->getTrace(); // Add the line throwing the exception to the backtrace. array_unshift($backtrace, array('line' => $exception->getLine(), 'file' => $exception->getFile())); @@ -741,17 +743,20 @@ function _drupal_decode_exception($exception) { // or in one of its global functions. $db_functions = array('db_query', 'pager_query', 'db_query_range', 'db_query_temporary', 'update_sql'); while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && - ((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE)) || + ((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || $caller['class'] == 'PDOStatement')) || in_array($caller['function'], $db_functions))) { // We remove that call. array_shift($backtrace); } + if (isset($exception->query_string, $exception->args)) { + $message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE); + } } $caller = _drupal_get_last_caller($backtrace); return array( '%type' => get_class($exception), - '%message' => $exception->getMessage(), + '%message' => $message, '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], diff --git a/includes/database/database.inc b/includes/database/database.inc index 60d4b415f..f1185c77a 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -595,13 +595,15 @@ abstract class DatabaseConnection extends PDO { catch (PDOException $e) { _db_check_install_needed(); if ($options['throw_exception']) { + // Add additional debug information. if ($query instanceof DatabaseStatementInterface) { - $query_string = $stmt->getQueryString(); + $e->query_string = $stmt->getQueryString(); } else { - $query_string = $query; + $e->query_string = $query; } - throw new PDOException($query_string . " - \n" . print_r($args, 1) . $e->getMessage()); + $e->args = $args; + throw $e; } return NULL; } diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc index ba82aa0b0..0f5627c2a 100644 --- a/includes/database/pgsql/database.inc +++ b/includes/database/pgsql/database.inc @@ -80,13 +80,15 @@ class DatabaseConnection_pgsql extends DatabaseConnection { catch (PDOException $e) { _db_check_install_needed(); if ($options['throw_exception']) { + // Add additional debug information. if ($query instanceof DatabaseStatementInterface) { - $query_string = $stmt->getQueryString(); + $e->query_string = $stmt->getQueryString(); } else { - $query_string = $query; + $e->query_string = $query; } - throw new PDOException($query_string . " - \n" . print_r($args, 1) . $e->getMessage()); + $e->args = $args; + throw $e; } return NULL; } |