You are here

protected function Schema::createIndexSql 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::createIndexSql()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::createIndexSql()

Returns the SQL needed to create an index.

Supports XML indexes. Incomplete.

Parameters

string $table: Table to create the index on.

string $name: Name of the index.

array $fields: Fields to be included in the Index.

mixed $xml_field: The xml field.

Return value

string SQL string.

1 call to Schema::createIndexSql()
Schema::addIndex in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add an index.

File

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

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function createIndexSql($table, $name, array $fields, $xml_field) {

  // Get information about current columns.
  $info = $this
    ->queryColumnInformation($table);

  // Flatten $fields array if neccesary.
  $fields = $this
    ->createKeySql($fields, TRUE);

  // XML indexes can only have 1 column.
  if (!empty($xml_field) && isset($fields[1])) {
    throw new \Exception("Cannot include an XML field on a multiple column index.");
  }

  // No more than one XML index per table.
  if ($xml_field && $this
    ->tableHasXmlIndex($table)) {
    throw new \Exception("Only one primary clustered XML index is allowed per table.");
  }
  if (empty($xml_field)) {
    $fields_csv = implode(', ', $fields);
    return "CREATE INDEX {$name}_idx ON [{{$table}}] ({$fields_csv})";
  }
  else {
    return "CREATE PRIMARY XML INDEX {$name}_idx ON [{{$table}}] ({$xml_field})";
  }
}