You are here

public function DatabaseConnection_sqlsrv::query_direct in Drupal driver for SQL Server and SQL Azure 7.3

Same name and namespace in other branches
  1. 7.2 sqlsrv/database.inc \DatabaseConnection_sqlsrv::query_direct()

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.

Parameters

mixed $query:

array $args:

mixed $options:

Return value

mixed

Throws

PDOException

4 calls to DatabaseConnection_sqlsrv::query_direct()
DatabaseConnection_sqlsrv::nextId in sqlsrv/database.inc
Override of DatabaseConnection::nextId().
DatabaseConnection_sqlsrv::popCommittableTransactions in sqlsrv/database.inc
Internal function: commit all the transaction layers that can commit.
DatabaseConnection_sqlsrv::pushTransaction in sqlsrv/database.inc
Summary of pushTransaction
DatabaseConnection_sqlsrv::rollback in sqlsrv/database.inc
Overriden.

File

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

Class

DatabaseConnection_sqlsrv
Summary of DatabaseConnection_sqlsrv

Code

public function query_direct($query, array $args = array(), $options = array()) {

  // Use default values if not already set.
  $options += $this
    ->defaultOptions();
  $stmt = NULL;
  try {

    // Bypass query preprocessing and use direct queries.
    $ctx = new \DatabaseContext($this, TRUE, TRUE);

    // Prepare the statement and execute it.
    $stmt = $this
      ->prepareQuery($query, $options);
    $stmt
      ->execute($args, $options);

    // Reset the context settings.
    unset($ctx);

    // Depending on the type of query we may need to return a different value.
    // See DatabaseConnection::defaultOptions() for a description of each
    // value.
    switch ($options['return']) {
      case Database::RETURN_STATEMENT:
        return $stmt;
      case Database::RETURN_AFFECTED:
        return $stmt
          ->rowCount();
      case Database::RETURN_INSERT_ID:
        return $this
          ->lastInsertId();
      case Database::RETURN_NULL:
        return NULL;
      default:
        throw new PDOException('Invalid return directive: ' . $options['return']);
    }
  } catch (PDOException $e) {

    // Most database drivers will return NULL here, but some of them
    // (e.g. the SQLite driver) may need to re-run the query, so the return
    // value will be the same as for static::query().
    return $this
      ->handleQueryException($e, $stmt, $args, $options);
  }
}