Esempio n. 1
0
        protected override string GetColumnSpec(DbColumnInfo column, DbScriptOptions options)
        {
            var  typeStr    = column.TypeInfo.DbTypeSpec;
            var  nullable   = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
            var  nullStr    = nullable ? "NULL" : "NOT NULL";
            var  strAutoInc = string.Empty;
            bool isNew      = options.IsSet(DbScriptOptions.NewColumn);

            if (isNew && column.Flags.IsSet(DbColumnFlags.Identity))
            {
                // MySql requires that auto-incr column is supported by a key - either a primary key, or an index
                var strKeyType = column.Flags.IsSet(DbColumnFlags.PrimaryKey) ? "PRIMARY KEY" : "KEY";
                strAutoInc = $"AUTO_INCREMENT, {strKeyType}({column.ColumnNameQuoted})";
            }
            string defaultStr = null;

            //Default constraint can be set only on new columns
            if (!string.IsNullOrWhiteSpace(column.DefaultExpression) && options.IsSet(DbScriptOptions.NewColumn))
            {
                defaultStr = "DEFAULT " + column.DefaultExpression;
            }
            var spec = $" {column.ColumnNameQuoted} {typeStr} {nullStr} {strAutoInc}";

            return(spec);
        }
Esempio n. 2
0
 public override void BuildColumnModifySql(DbObjectChange change, DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
 {
     var colSpec = GetColumnSpec(column, options);
       var tbl = column.Table;
       var scriptType = options.IsSet(DbScriptOptions.CompleteColumnSetup) ? DbScriptType.ColumnSetupComplete : DbScriptType.ColumnModify;
       change.AddScript(scriptType, "ALTER TABLE {0} MODIFY COLUMN {1};", tbl.FullName, colSpec);
 }
Esempio n. 3
0
        public override void BuildColumnModifySql(DbObjectChange change, DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
        {
            var colSpec    = GetColumnSpec(column, options);
            var tbl        = column.Table;
            var scriptType = options.IsSet(DbScriptOptions.CompleteColumnSetup) ? DbScriptType.ColumnSetupComplete : DbScriptType.ColumnModify;

            change.AddScript(scriptType, $"ALTER TABLE {tbl.FullName} MODIFY COLUMN {colSpec};");
        }
Esempio n. 4
0
 //ALTER TABLE employees ALTER COLUMN [employee_name] nvarchar(100) Null;
 public virtual void BuildColumnModifySql(DbObjectChange change, DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
 {
     var scriptType = options.IsSet(DbScriptOptions.CompleteColumnSetup) ? DbScriptType.ColumnSetupComplete : DbScriptType.ColumnModify;
       if(ShouldResetNullsToDefault(column)) {
     BuildColumnSetDefaultValuesSql(change, column);
     scriptType = DbScriptType.ColumnSetupComplete;
       }
       var colSpec = GetColumnSpec(column);
       change.AddScript(scriptType,
     "ALTER TABLE {0} ALTER COLUMN {1};", column.Table.FullName, colSpec);
 }
Esempio n. 5
0
        //ALTER TABLE employees ALTER COLUMN [employee_name] nvarchar(100) Null;
        public virtual void BuildColumnModifySql(DbObjectChange change, DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
        {
            var scriptType = options.IsSet(DbScriptOptions.CompleteColumnSetup) ? DbScriptType.ColumnSetupComplete : DbScriptType.ColumnModify;

            if (ShouldResetNullsToDefault(column))
            {
                BuildColumnSetDefaultValuesSql(change, column);
                scriptType = DbScriptType.ColumnSetupComplete;
            }
            var colSpec = GetColumnSpec(column);

            change.AddScript(scriptType, $"ALTER TABLE {column.Table.FullName} ALTER COLUMN {colSpec};");
        }
Esempio n. 6
0
        protected virtual string GetColumnSpec(DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
        {
            var    typeStr    = column.TypeInfo.DbTypeSpec;
            var    nullable   = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
            var    nullStr    = nullable ? "NULL" : "NOT NULL";
            string defaultStr = null;

            if (!string.IsNullOrWhiteSpace(column.DefaultExpression))
            {
                defaultStr = "DEFAULT " + column.DefaultExpression;
            }
            var spec = $" {column.ColumnNameQuoted} {typeStr} {defaultStr} {nullStr}";

            return(spec);
        }
Esempio n. 7
0
        protected virtual string GetColumnSpec(DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
        {
            var    typeStr    = column.TypeInfo.SqlTypeSpec;
            var    nullable   = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
            var    nullStr    = nullable ? "NULL" : "NOT NULL";
            string defaultStr = null;

            if (!string.IsNullOrWhiteSpace(column.DefaultExpression))
            {
                defaultStr = "DEFAULT " + column.DefaultExpression;
            }
            var spec = string.Format(" \"{0}\" {1} {2} {3}", column.ColumnName, typeStr, defaultStr, nullStr);

            return(spec);
        }
Esempio n. 8
0
 protected override string GetColumnSpec(DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
 {
     var typeStr = column.TypeInfo.SqlTypeSpec;
       var nullable = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
       var nullStr = nullable ? "NULL" : "NOT NULL";
       var idStr = string.Empty;
       bool isNew = column.Peer == null;
       if(isNew && column.Flags.IsSet(DbColumnFlags.Identity)) {
     idStr = "IDENTITY(1,1)";
       }
       string defaultStr = null;
       //Default constraint can be set only on new columns in SQL server
       if(!string.IsNullOrWhiteSpace(column.DefaultExpression) && isNew)
     defaultStr = "DEFAULT " + column.DefaultExpression;
       var spec = string.Format(" \"{0}\" {1} {2} {3} {4}", column.ColumnName, typeStr, idStr, defaultStr, nullStr);
       return spec;
 }
Esempio n. 9
0
 protected override string GetColumnSpec(DbColumnInfo column, DbScriptOptions options)
 {
     var typeStr = column.TypeInfo.SqlTypeSpec;
       var nullable = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
       var nullStr = nullable ? "NULL" : "NOT NULL";
       var strAutoInc = string.Empty;
       bool isNew = column.Peer == null;
       if(isNew && column.Flags.IsSet(DbColumnFlags.Identity)) {
     // MySql requires that auto-incr column is supported by a key - either a primary key, or an index
     var strKeyType = column.Flags.IsSet(DbColumnFlags.PrimaryKey) ? "PRIMARY KEY" : "KEY";
     strAutoInc = string.Format("AUTO_INCREMENT, {0}(\"{1}\")", strKeyType, column.ColumnName);
       }
       string defaultStr = null;
       //Default constraint can be set only on new columns
       if(!string.IsNullOrWhiteSpace(column.DefaultExpression) && options.IsSet(DbScriptOptions.NewColumn))
     defaultStr = "DEFAULT " + column.DefaultExpression;
       var spec = string.Format(@" ""{0}"" {1} {2} {3}", column.ColumnName, typeStr, nullStr, strAutoInc);
       return spec;
 }
Esempio n. 10
0
        protected override string GetColumnSpec(DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
        {
            var  typeStr  = column.TypeInfo.DbTypeSpec;
            var  nullable = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
            var  nullStr  = nullable ? "NULL" : "NOT NULL";
            var  idStr    = string.Empty;
            bool isNew    = column.Peer == null;

            if (isNew && column.Flags.IsSet(DbColumnFlags.Identity))
            {
                idStr = "IDENTITY(1,1)";
            }
            string defaultStr = null;

            //Default constraint can be set only on new columns in SQL server
            if (!string.IsNullOrWhiteSpace(column.DefaultExpression) && isNew)
            {
                defaultStr = "DEFAULT " + column.DefaultExpression;
            }
            var spec = $" {column.ColumnNameQuoted} {typeStr} {idStr} {defaultStr} {nullStr}";

            return(spec);
        }
Esempio n. 11
0
 protected virtual string GetColumnSpec(DbColumnInfo column, DbScriptOptions options = DbScriptOptions.None)
 {
     var typeStr = column.TypeInfo.SqlTypeSpec;
       var nullable = options.IsSet(DbScriptOptions.ForceNull) || column.Flags.IsSet(DbColumnFlags.Nullable);
       var nullStr = nullable ? "NULL" : "NOT NULL";
       string defaultStr = null;
       if(!string.IsNullOrWhiteSpace(column.DefaultExpression))
     defaultStr = "DEFAULT " + column.DefaultExpression;
       var spec = string.Format(" \"{0}\" {1} {2} {3}", column.ColumnName, typeStr, defaultStr, nullStr);
       return spec;
 }