public function Schema::getCollation in Drupal driver for SQL Server and SQL Azure 3.0.x
Same name and namespace in other branches
- 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::getCollation()
Get the collation.
Get the collation of current connection whether it has or not a database defined in it.
Parameters
string $table: Table name.
string $column: Column name.
Return value
string Collation type.
2 calls to Schema::getCollation()
- Schema::createFieldSql in drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Schema.php - Create Field SQL.
- Schema::isUtf8 in drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Schema.php - Is the database configured as UTF8 character encoding?
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Schema.php, line 1707
Class
Namespace
Drupal\Driver\Database\sqlsrvCode
public function getCollation($table = NULL, $column = NULL) {
// No table or column provided, then get info about
// database (if exists) or server default collation.
if (empty($table) && empty($column)) {
// Database is defaulted from active connection.
$options = $this->connection
->getConnectionOptions();
$database = $options['database'];
if (!empty($database)) {
// Default collation for specific table.
// CONVERT defaults to returning only 30 chars.
$sql = "SELECT CONVERT (varchar(50), DATABASEPROPERTYEX('{$database}', 'collation'))";
return $this->connection
->queryDirect($sql)
->fetchField();
}
else {
// Server default collation.
$sql = "SELECT SERVERPROPERTY ('collation') as collation";
return $this->connection
->queryDirect($sql)
->fetchField();
}
}
$sql = <<<EOF
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLLATION_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ':schema'
AND TABLE_NAME = ':table'
AND COLUMN_NAME = ':column'
EOF;
$params = [];
$params[':schema'] = $this
->getDefaultSchema();
$params[':table'] = $table;
$params[':column'] = $column;
$result = $this->connection
->queryDirect($sql, $params)
->fetchObject();
return $result->COLLATION_NAME;
}