You are here

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

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

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

Overrides DatabaseConnection::query

2 calls to DatabaseConnection_sqlsrv::query()
DatabaseConnection_sqlsrv::queryRange in sqlsrv/database.inc
Override of DatabaseConnection::queryRange().
DatabaseConnection_sqlsrv::queryTemporary in sqlsrv/database.inc
Override of DatabaseConnection::queryTemporary().

File

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

Class

DatabaseConnection_sqlsrv
Summary of DatabaseConnection_sqlsrv

Code

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

  // 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 DatabaseStatementInterface) {
      $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' => TRUE,
      ));
      $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:
        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);
  }
}