You are here

public function DatabaseConnection_sqlsrv::queryTemporary in Drupal driver for SQL Server and SQL Azure 7.2

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

Override of DatabaseConnection::queryTemporary().

@status tested

Overrides DatabaseConnection::queryTemporary

File

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

Class

DatabaseConnection_sqlsrv
Summary of DatabaseConnection_sqlsrv

Code

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

  // Generate a new GLOBAL temporary table name and protect it from prefixing.
  // SQL Server requires that temporary tables to be non-qualified.
  $tablename = '##' . $this
    ->generateTemporaryTableName();
  $prefixes = $this->prefixes;
  $prefixes[$tablename] = '';
  $this
    ->setPrefix($prefixes);

  // Having comments in the query can be tricky and break the SELECT FROM  -> SELECT INTO conversion
  $query = $this
    ->schema()
    ->removeSQLComments($query);

  // Replace SELECT xxx FROM table by SELECT xxx INTO #table FROM table.
  $query = preg_replace('/^SELECT(.*?)FROM/is', 'SELECT$1 INTO ' . $tablename . ' FROM', $query);
  $this
    ->query($query, $args, $options);
  return $tablename;
}