Connection::handleQueryException

protected Connection::handleQueryException(\PDOException $e, $query, array $args = array(), $options = array())

Wraps and re-throws any PDO exception thrown by static::query().

Parameters

\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.

Return value

\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.

Throws

\Drupal\Core\Database\DatabaseExceptionWrapper

\Drupal\Core\Database\IntegrityConstraintViolationException

File

core/lib/Drupal/Core/Database/Connection.php, line 659

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

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;
}
doc_Drupal
2016-10-29 08:55:51
Comments
Leave a Comment

Please login to continue.