You are here

private function DatabaseSchema_sqlsrv::defaultValueExpression in Drupal driver for SQL Server and SQL Azure 7.2

Same name and namespace in other branches
  1. 7.3 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::defaultValueExpression()

Get the SQL expression for a default value.

Parameters

mixed $table:

mixed $field:

mixed $default:

3 calls to DatabaseSchema_sqlsrv::defaultValueExpression()
DatabaseSchema_sqlsrv::addField in sqlsrv/schema.inc
Override DatabaseSchema::addField().
DatabaseSchema_sqlsrv::changeField in sqlsrv/schema.inc
Override DatabaseSchema::changeField().
DatabaseSchema_sqlsrv::createFieldSql in sqlsrv/schema.inc
Create an SQL string for a field to be used in table creation or alteration.

File

sqlsrv/schema.inc, line 721
Database schema code for Microsoft SQL Server database servers.

Class

DatabaseSchema_sqlsrv

Code

private function defaultValueExpression($sqlsr_type, $default) {

  // The actual expression depends on the target data type as it might require conversions.
  $result = is_string($default) ? "'" . addslashes($default) . "'" : $default;
  if (\DatabaseUtils::GetMSSQLType($sqlsr_type) == 'varbinary') {
    $default = addslashes($default);
    $result = "CONVERT({$sqlsr_type}, '{$default}')";
  }
  return $result;
}