You are here

public function Scheme::StatisticsExists in Drupal driver for SQL Server and SQL Azure 8.2

Check if a statistic already exists.

Parameters

string $table:

string $statistics:

Return value

bool

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Scheme.php, line 143

Class

Scheme

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function StatisticsExists($table, $statistics) {
  $query = <<<EOF
SELECT stat.name AS Statistics,
 OBJECT_NAME(stat.object_id) AS Object,
 COL_NAME(scol.object_id, scol.column_id) AS Column
FROM sys.stats AS stat (NOLOCK) Join sys.stats_columns AS scol (NOLOCK)
 ON stat.stats_id = scol.stats_id AND stat.object_id = scol.object_id
 INNER JOIN sys.tables AS tab (NOLOCK) on tab.object_id = stat.object_id
WHERE OBJECT_NAME(stat.object_id) = :table AND
stat.name = :statistics
EOF;
  return $this->cnn
    ->query_execute($query, array(
    ':table' => $table,
    ':statistics' => $statistics,
  ))
    ->fetchField() !== false;
}