IsDate() 공개 정적인 메소드

public static IsDate ( SqlDbType sqlDbType ) : bool
sqlDbType SqlDbType
리턴 bool
예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
        }