public static IsNumber ( SqlDbType sqlDbType ) : bool | ||
sqlDbType | SqlDbType | |
Результат | bool |
private static SqlPreCommand AlterTableAddColumnDefault(ITable table, IColumn column, Replacements rep) { bool temporalDefault = !column.Nullable && !column.Identity && column.Default == null; if (!temporalDefault) { return(SqlBuilder.AlterTableAddColumn(table, column)); } string defaultValue = rep.Interactive ? SafeConsole.AskString("Default value for '{0}.{1}'? (or press enter) ".FormatWith(table.Name.Name, column.Name), stringValidator: str => null) : ""; if (defaultValue == "null") { return(SqlBuilder.AlterTableAddColumn(table, column)); } try { column.Default = defaultValue; if (column.Default.HasText() && SqlBuilder.IsString(column.SqlDbType) && !column.Default.Contains("'")) { column.Default = "'" + column.Default + "'"; } if (string.IsNullOrEmpty(column.Default)) { column.Default = SqlBuilder.IsNumber(column.SqlDbType) ? "0" : SqlBuilder.IsString(column.SqlDbType) ? "''" : SqlBuilder.IsDate(column.SqlDbType) ? "GetDate()" : "?"; } return(SqlPreCommand.Combine(Spacing.Simple, SqlBuilder.AlterTableAddColumn(table, column), SqlBuilder.DropDefaultConstraint(table.Name, column.Name))); } finally { column.Default = null; } }
public static string GetDefaultValue(ITable table, IColumn column, Replacements rep) { string defaultValue = rep.Interactive ? SafeConsole.AskString("Default value for '{0}.{1}'? (or press enter) ".FormatWith(table.Name.Name, column.Name), stringValidator: str => null) : ""; if (defaultValue == "force") { return(defaultValue); } if (defaultValue.HasText() && SqlBuilder.IsString(column.SqlDbType) && !defaultValue.Contains("'")) { defaultValue = "'" + defaultValue + "'"; } if (string.IsNullOrEmpty(defaultValue)) { defaultValue = SqlBuilder.IsNumber(column.SqlDbType) ? "0" : SqlBuilder.IsString(column.SqlDbType) ? "''" : SqlBuilder.IsDate(column.SqlDbType) ? "GetDate()" : "?"; } return(defaultValue); }