You are here

public function Connection::handleQueryException in Drupal driver for SQL Server and SQL Azure 8

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::handleQueryException()

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

Overrides Connection::handleQueryException

2 calls to Connection::handleQueryException()
Connection::query in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
This method is overriden to manage the insecure (EMULATE_PREPARE) behaviour to prevent some compatibility issues with SQL Server.
Connection::query_direct in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Like query but with no insecure detection or query preprocessing. The caller is sure that his query is MS SQL compatible! Used internally from the schema class, but could be called from anywhere.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php, line 553
Definition of Drupal\Driver\Database\sqlsrv\Connection

Class

Connection
Temporary tables: temporary table support is done by means of global temporary tables (#) to avoid the use of DIRECT QUERIES. You can enable and disable the use of direct queries with $this->driver_settings->defaultDirectQuery =…

Namespace

Drupal\Driver\Database\sqlsrv

Code

public 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.
    if ($query instanceof StatementInterface) {
      $query_string = $query
        ->getQueryString();
    }
    else {
      $query_string = $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);
    }
    $exception->query_string = $query_string;
    $exception->args = $args;
    throw $exception;
  }
  return NULL;
}