示例#1
0
        private void FillRealTableSchema(ModifiedColumnsCollection cols)
        {
            var columns = cols.AllColumnsNames;
            var all     = _db.Query <ColumnSchema>(
                @"select COLUMN_NAME as ColumnName, DATA_TYPE as DataType
, cast (CHARACTER_MAXIMUM_LENGTH as varchar(5))as CharacterMaximumLength, cast (NUMERIC_PRECISION as varchar(5)) as NumericPrecision, cast (NUMERIC_SCALE as varchar(5)) as NumericScale, COLLATION_NAME as CollationName from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @0 and COLUMN_NAME in (@1)", cols.TableName, columns);

            foreach (var cs in all)
            {
                var column = cols[cs.ColumnName];
                column.Modifications.Current.Type      = ExtractType(cs);
                column.Modifications.Current.Collation = cs.CollationName;
            }

            var defaults = _db.Query <dynamic>(@"select c.name as colname, d.name as defname
from sys.tables t
    join
    sys.default_constraints d
        on d.parent_object_id = t.object_id
    join
    sys.columns c
        on c.object_id = t.object_id
        and c.column_id = d.parent_column_id
where t.name = @0
and c.name in (@1)", cols.TableName, columns);

            foreach (var def in defaults)
            {
                var column = cols[def.colname];
                column.Modifications.Current.DefaultConstraintName = def.defname;
            }
        }
        private void FillRealTableSchema(ModifiedColumnsCollection cols)
        {
            var columns = cols.AllColumnsNames;
            var all = _db.Query<ColumnSchema>(
                @"select COLUMN_NAME as ColumnName, DATA_TYPE as DataType
, cast (CHARACTER_MAXIMUM_LENGTH as varchar(5))as CharacterMaximumLength, cast (NUMERIC_PRECISION as varchar(5)) as NumericPrecision, cast (NUMERIC_SCALE as varchar(5)) as NumericScale, COLLATION_NAME as CollationName from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = @0 and COLUMN_NAME in (@1)", cols.TableName, columns);
            foreach (var cs in all)
            {
                var column = cols[cs.ColumnName];
                column.Modifications.Current.Type = ExtractType(cs);
                column.Modifications.Current.Collation = cs.CollationName;
            }

            var defaults = _db.Query<dynamic>(@"select c.name as colname, d.name as defname
from sys.tables t
    join
    sys.default_constraints d
        on d.parent_object_id = t.object_id
    join
    sys.columns c
        on c.object_id = t.object_id
        and c.column_id = d.parent_column_id
where t.name = @0
and c.name in (@1)", cols.TableName, columns);
            foreach (var def in defaults)
            {
                var column = cols[def.colname];
                column.Modifications.Current.DefaultConstraintName = def.defname;
            }
        }
示例#3
0
 private void Init(string name)
 {
     Name = name;
     Options = new DbEngineOptions();
     Columns = new ColumnsCollection();
     Constraints = new ConstraintsCollection(this);
     Indexes = new IndexCollection(this);
     ModifiedColumns = new ModifiedColumnsCollection(name);
 }
示例#4
0
 public override void Write(ModifiedColumnsCollection columns)
 {
     if (!columns.HasAnyChange)
     {
         return;
     }
     FillRealTableSchema(columns);
     base.Write(columns);
 }
示例#5
0
        public TableSchema(string name)
        {
            Name = name;
            Options= new DbEngineOptions();
            Columns= new ColumnsCollection();
            Constraints = new ConstraintsCollection(this);
            Indexes= new IndexCollection(this);

            ModifiedColumns=new ModifiedColumnsCollection(name);
        }
        public virtual void Write(ModifiedColumnsCollection columns)
        {
            _columns = columns;
            if (!columns.HasAnyChange) return;
            var changes = columns.ChangedColumns;

            foreach (var column in columns.Where(ShouldDropDefault))
            {
                Writer.WriteDropDefault(column);
            }

            foreach (var ch in changes.Where(c => c.HasChangedStructure))
            {
                Writer.WriteColumnChanges(ch);
            }

            foreach (var column in changes.Where(d => d.DefaultValue != null))
            {
                Writer.WriteSetDefault(column);
            }
        }
示例#7
0
        public virtual void Write(ModifiedColumnsCollection columns)
        {
            _columns = columns;
            if (!columns.HasAnyChange)
            {
                return;
            }
            var changes = columns.ChangedColumns;

            foreach (var column in columns.Where(ShouldDropDefault))
            {
                Writer.WriteDropDefault(column);
            }

            foreach (var ch in changes.Where(c => c.HasChangedStructure))
            {
                Writer.WriteColumnChanges(ch);
            }

            foreach (var column in changes.Where(d => d.DefaultValue != null))
            {
                Writer.WriteSetDefault(column);
            }
        }
 public override void Write(ModifiedColumnsCollection columns)
 {
     if (!columns.HasAnyChange) return;
     FillRealTableSchema(columns);
     base.Write(columns);
 }