protected function DatabaseSchema_sqlsrv::processField 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::processField()
- 7 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::processField()
Set database-engine specific properties for a field.
Parameters
$field: A field description array, as specified in the schema documentation.
3 calls to DatabaseSchema_sqlsrv::processField()
- DatabaseSchema_sqlsrv::addField in sqlsrv/
schema.inc - Override DatabaseSchema::addField().
- DatabaseSchema_sqlsrv::changeField in sqlsrv/
schema.inc - Override DatabaseSchema::changeField().
- DatabaseSchema_sqlsrv::createTableSql in sqlsrv/
schema.inc - Generate SQL to create a new table from a Drupal schema definition.
File
- sqlsrv/
schema.inc, line 808 - Database schema code for Microsoft SQL Server database servers.
Class
Code
protected function processField($field) {
// Default size to normal.
if (!isset($field['size'])) {
$field['size'] = 'normal';
}
// Set the correct database-engine specific datatype.
if (!isset($field['sqlsrv_type'])) {
$map = $this
->getFieldTypeMap();
$field['sqlsrv_type'] = $map[$field['type'] . ':' . $field['size']];
}
// Serial is identity.
if (isset($field['type']) && $field['type'] == 'serial') {
$field['identity'] = TRUE;
}
// If this is a text field.
if (!isset($field['sqlsrv_is_text'])) {
$field['sqlsrv_is_text'] = in_array($field['sqlsrv_type'], array(
'char',
'varchar',
'text',
'nchar',
'nvarchar',
'ntext',
));
}
// Collation only makes sense for text fields
// Detect target collation
if ($this->use_legacy_collations == FALSE && $field['sqlsrv_is_text'] && !isset($field['sqlsrv_collation'])) {
if (!empty($field['collation'])) {
// Try to match to an SQL Server collation
switch ($field['collation']) {
case 'ascii_bin':
$field['sqlsrv_collation'] = 'Latin1_General_BIN';
break;
}
}
// If still no collation, resort to default behaviour.
if (empty($field['sqlsrv_collation'])) {
if ($field['sqlsrv_is_text'] === TRUE && isset($field['binary']) && $field['binary'] === TRUE) {
$field['sqlsrv_collation'] = self::DEFAULT_COLLATION_CS;
}
else {
$field['sqlsrv_collation'] = self::DEFAULT_COLLATION_CI;
}
}
}
// The full native type (TYPE (LENGTH))
if (!isset($field['sqlsrv_type_full'])) {
$sqlsrv_type_full = $field['sqlsrv_type'];
if ($field['sqlsrv_is_text'] === TRUE && !empty($field['length'])) {
$sqlsrv_type_full .= '(' . $field['length'] . ')';
}
elseif (in_array($field['sqlsrv_type'], array(
'numeric',
'decimal',
)) && isset($field['precision']) && isset($field['scale'])) {
// Maximum precision for SQL Server 2008 or greater is 38.
// For previous versions it's 28.
if ($field['precision'] > 38) {
$field['precision'] = 38;
}
$sqlsrv_type_full .= '(' . $field['precision'] . ', ' . $field['scale'] . ')';
}
$field['sqlsrv_type_full'] = $sqlsrv_type_full;
}
return $field;
}