public function DatabaseSchema_sqlsrv::tableExists in Drupal driver for SQL Server and SQL Azure 7.2
Same name and namespace in other branches
- 7.3 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::tableExists()
- 7 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::tableExists()
Find if a table already exists. Results are cached, use $reset = TRUE to get a fresh copy.
Parameters
$table: Name of the table.
Return value
True if the table exists, false otherwise.
Overrides DatabaseSchema::tableExists
8 calls to DatabaseSchema_sqlsrv::tableExists()
- DatabaseSchema_sqlsrv::addField in sqlsrv/
schema.inc - Override DatabaseSchema::addField().
- DatabaseSchema_sqlsrv::addIndex in sqlsrv/
schema.inc - Override DatabaseSchema::addIndex().
- DatabaseSchema_sqlsrv::addPrimaryKey in sqlsrv/
schema.inc - Override DatabaseSchema::addPrimaryKey().
- DatabaseSchema_sqlsrv::addUniqueKey in sqlsrv/
schema.inc - Override DatabaseSchema::addUniqueKey().
- DatabaseSchema_sqlsrv::createTable in sqlsrv/
schema.inc - {@Inheritdoc}
File
- sqlsrv/
schema.inc, line 382 - Database schema code for Microsoft SQL Server database servers.
Class
Code
public function tableExists($table, $reset = FALSE) {
if (empty($table)) {
return FALSE;
}
// Do not cache temporary tables (#)
if (!$reset && $table[0] != '#' && ($cache = fastcache::cache_get($table, 'tableExists'))) {
return $cache->data;
}
// 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;
if ($table[0] != '#') {
fastcache::cache_set($table, $exists, 'tableExists');
}
return $exists;
}