You are here

protected function DatabaseStatement_sqlsrv::throwPDOException in Drupal driver for SQL Server and SQL Azure 7.2

Same name and namespace in other branches
  1. 7.3 sqlsrv/database.inc \DatabaseStatement_sqlsrv::throwPDOException()

Throw a PDO Exception based on the last PDO error.

@status: Unfinished.

1 call to DatabaseStatement_sqlsrv::throwPDOException()
DatabaseStatement_sqlsrv::execute in sqlsrv/database.inc
Executes a prepared statement

File

sqlsrv/database.inc, line 1013
Database interface code for Microsoft SQL Server.

Class

DatabaseStatement_sqlsrv

Code

protected function throwPDOException(&$statement = NULL) {

  // This is what a SQL Server PDO "no error" looks like.
  $null_error = array(
    0 => '00000',
    1 => NULL,
    2 => NULL,
  );

  // The implementation in Drupal's Core StatementPrefetch Class
  // takes for granted that the error information is in the PDOConnection
  // but it is regularly held in the PDOStatement.
  $error_info_connection = $this->dbh
    ->errorInfo();
  $error_info_statement = !empty($statement) ? $statement
    ->errorInfo() : $null_error;

  // TODO: Concatenate error information when both connection
  // and statement error info are valid.
  // We rebuild a message formatted in the same way as PDO.
  $error_info = $error_info_connection === $null_error ? $error_info_statement : $error_info_connection;
  $exception = new PDOException("SQLSTATE[" . $error_info[0] . "]: General error " . $error_info[1] . ": " . $error_info[2]);
  $exception->errorInfo = $error_info;
  unset($statement);
  throw $exception;
}