protected function DatabaseSchema_sqlsrv::createFieldSql 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::createFieldSql()
- 7 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::createFieldSql()
Create an SQL string for a field to be used in table creation or alteration.
Before passing a field out of a schema definition into this function it has to be processed by _db_process_field().
Parameters
$table: The name of the table.
$name: Name of the field.
$spec: The field specification, as per the schema data structure format.
3 calls to DatabaseSchema_sqlsrv::createFieldSql()
- 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 684 - Database schema code for Microsoft SQL Server database servers.
Class
Code
protected function createFieldSql($table, $name, $spec, $skip_checks = FALSE) {
$sql = $this->connection
->quoteIdentifier($name) . ' ' . $spec['sqlsrv_type_full'];
// When binary is true, case sensitivity is requested.
if (isset($spec['sqlsrv_collation'])) {
$sql .= ' COLLATE ' . $spec['sqlsrv_collation'];
}
if (isset($spec['not null']) && $spec['not null'] == TRUE) {
$sql .= ' NOT NULL';
}
if (!$skip_checks) {
if (isset($spec['default'])) {
// Use a prefixed table.
$table_prefixed = $this->connection
->prefixTables('{' . $table . '}');
$default = $this
->defaultValueExpression($spec['sqlsrv_type'], $spec['default']);
$sql .= " CONSTRAINT {$table_prefixed}_{$name}_df DEFAULT {$default}";
}
if (!empty($spec['identity'])) {
$sql .= ' IDENTITY';
}
if (!empty($spec['unsigned'])) {
$sql .= ' CHECK (' . $this->connection
->quoteIdentifier($name) . ' >= 0)';
}
}
return $sql;
}