protected Connection::handleQueryException(\PDOException $e, $query, array $args = array(), $options = array())
Wraps and re-throws any PDO exception thrown by static::query().
\PDOException $e: The exception thrown by static::query().
$query: The query executed by static::query().
array $args: An array of arguments for the prepared statement.
array $options: An associative array of options to control how the query is run.
\Drupal\Core\Database\StatementInterface|int|null Most database drivers will return NULL when a PDO exception is thrown for a query, but some of them may need to re-run the query, so they can also return a \Drupal\Core\Database\StatementInterface object or an integer.
\Drupal\Core\Database\DatabaseExceptionWrapper
\Drupal\Core\Database\IntegrityConstraintViolationException
protected function handleQueryException(\PDOException $e, $query, array $args = array(), $options = array()) { if ($options['throw_exception']) { // Wrap the exception in another exception, because PHP does not allow // overriding Exception::getMessage(). Its message is the extra database // debug information. $query_string = ($query instanceof StatementInterface) ? $query->getQueryString() : $query; $message = $e->getMessage() . ": " . $query_string . "; " . print_r($args, TRUE); // Match all SQLSTATE 23xxx errors. if (substr($e->getCode(), -6, -3) == '23') { $exception = new IntegrityConstraintViolationException($message, $e->getCode(), $e); } else { $exception = new DatabaseExceptionWrapper($message, 0, $e); } throw $exception; } return NULL; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Connection.php/function/Connection::handleQueryException/8.1.x