You are here

public function Connection::escapeTable 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::escapeTable()

Override DatabaseConnection::escapeTable().

@status needswork

Overrides Connection::escapeTable

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php, line 780
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 escapeTable($table) {

  // A static cache is better suited for this.
  static $tables = array();
  if (isset($tables[$table])) {
    return $tables[$table];
  }

  // Rescue the # prefix from the escaping.
  $is_temporary = $table[0] == '#';
  $is_temporary_global = $is_temporary && isset($table[1]) && $table[1] == '#';

  // Any temporary table prefix will be removed.
  $result = preg_replace('/[^A-Za-z0-9_.]+/', '', $table);

  // Restore the temporary prefix.
  if ($is_temporary) {
    if ($is_temporary_global) {
      $result = '##' . $result;
    }
    else {
      $result = '#' . $result;
    }
  }
  $tables[$table] = $result;
  return $result;
}