You are here

public function Schema::tableExists 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/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::tableExists()
  2. 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::tableExists()

Find if a table already exists.

Parameters

$table: Name of the table.

Return value

True if the table exists, false otherwise.

Overrides Schema::tableExists

8 calls to Schema::tableExists()
Schema::addField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addField().
Schema::addIndex in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addIndex().
Schema::addPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addPrimaryKey().
Schema::addUniqueKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addUniqueKey().
Schema::createTable in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
{@Inheritdoc}

... See full list

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 374
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function tableExists($table) {

  // If $table is NULL, then $table[0] will generate a notice.
  if (empty($table)) {
    return FALSE;
  }

  // Temporary tables and regular tables cannot be verified in the same way.
  $query = NULL;
  if ($table[0] == '#') {
    $query = "SELECT 1 FROM tempdb.sys.tables WHERE name like '" . $this->connection
      ->prefixTables('{' . $table . '}') . "%'";
  }
  else {
    $query = "SELECT 1 FROM INFORMATION_SCHEMA.tables WHERE table_name = '" . $this->connection
      ->prefixTables('{' . $table . '}') . "'";
  }
  $exists = $this->connection
    ->query_direct($query)
    ->fetchField() !== FALSE;
  return $exists;
}