You are here

public function Schema::tableExists in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::tableExists()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::tableExists()

Temporary tables and regular tables cannot be verified in the same way.

Overrides Schema::tableExists

10 calls to Schema::tableExists()
Schema::addField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add a new field to a table.
Schema::addIndex in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add an index.
Schema::addPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add a primary key.
Schema::addUniqueKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add a unique key.
Schema::createTable in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Create a new table from a Drupal table definition.

... See full list

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 780

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function tableExists($table) {
  if (empty($table)) {
    return FALSE;
  }

  // Temporary tables and regular tables cannot be verified in the same way.
  $query = NULL;
  $prefixInfo = $this
    ->getPrefixInfo($table, TRUE);
  $args = [];
  if ($this->connection
    ->isTemporaryTable($table)) {
    $query = "SELECT 1 FROM tempdb.sys.tables WHERE [object_id] = OBJECT_ID(:table)";
    $args = [
      ':table' => 'tempdb.[' . $this
        ->getDefaultSchema() . '].[' . $prefixInfo['table'] . ']',
    ];
  }
  else {
    $query = "SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE [table_name] = :table";
    $args = [
      ':table' => $prefixInfo['table'],
    ];
  }
  return (bool) $this->connection
    ->queryDirect($query, $args)
    ->fetchField();
}