You are here

public function Connection::query in Drupal driver for SQL Server and SQL Azure 8.2

Same name in this branch
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::query()
  2. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/PDO/Connection.php \Drupal\Driver\Database\sqlsrv\PDO\Connection::query()
Same name and namespace in other branches
  1. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::query()
  2. 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::query()

This method is overriden to manage the insecure (EMULATE_PREPARE) behaviour to prevent some compatibility issues with SQL Server.

Overrides Connection::query

2 calls to Connection::query()
Connection::queryRange in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Runs a limited-range query on this database object.
Connection::queryTemporary in drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php
Runs a SELECT query and stores its results in a temporary table.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php, line 485
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($query, array $args = [], $options = []) {

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

    // We allow either a pre-bound statement object or a literal string.
    // In either case, we want to end up with an executed statement object,
    // which we pass to PDOStatement::execute.
    if ($query instanceof StatementInterface) {
      $stmt = $query;
      $stmt
        ->execute(null, $options);
    }
    else {
      $this
        ->expandArguments($query, $args);
      $insecure = isset($options['insecure']) ? $options['insecure'] : false;

      // Try to detect duplicate place holders, this check's performance
      // is not a good addition to the driver, but does a good job preventing
      // duplicate placeholder errors.
      $argcount = count($args);
      if ($insecure === true || $argcount >= 2100 || $argcount != substr_count($query, ':')) {
        $insecure = true;
      }
      $stmt = $this
        ->prepareQuery($query, array(
        'insecure' => $insecure,
      ));
      $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);
  }
}