You are here

public function Connection::query_direct 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::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 Connection::query_direct()
Connection::nextId in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Override of DatabaseConnection::nextId().
Connection::popCommittableTransactions in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Internal function: commit all the transaction layers that can commit.
Connection::pushTransaction in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Summary of pushTransaction
Connection::rollback in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Overriden.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php, line 592
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 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);
    $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:
        $stmt->allowRowCount = TRUE;
        return $stmt
          ->rowCount();
      case Database::RETURN_INSERT_ID:
        return $this->connection
          ->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, $query, $args, $options);
  }
}