You are here

public function Connection::queryDirect in Drupal driver for SQL Server and SQL Azure 4.1.x

Same name and namespace in other branches
  1. 4.2.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::queryDirect()
  2. 3.1.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::queryDirect()
  3. 4.0.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::queryDirect()

Like query but with no query preprocessing.

The caller is sure that the query is MS SQL compatible! Used internally from the schema class, but could be called from anywhere.

Parameters

string $query: Query.

array $args: Query arguments.

mixed $options: Query options.

Return value

mixed Query result.

Throws

\PDOException

3 calls to Connection::queryDirect()
Connection::nextId in src/Driver/Database/sqlsrv/Connection.php
Retrieves a unique ID from a given sequence.
Connection::pushTransaction in src/Driver/Database/sqlsrv/Connection.php
Using SQL Server query syntax.
Connection::rollBack in src/Driver/Database/sqlsrv/Connection.php
Using SQL Server query syntax.

File

src/Driver/Database/sqlsrv/Connection.php, line 778

Class

Connection
Sqlsvr implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\sqlsrv\Driver\Database\sqlsrv

Code

public function queryDirect($query, array $args = [], $options = []) {

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

    // Core tests run faster without emulating.
    $direct_query_options = [
      'direct_query' => TRUE,
      'bypass_preprocess' => TRUE,
      'emulate_prepares' => FALSE,
    ];
    $stmt = $this
      ->prepareStatement($query, $direct_query_options + $options);
    $stmt
      ->execute($args, $options);

    // 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);
  }
}