public void WriteColumnsChanges(TableSchema table)
        {
            var mods = table.ModifiedColumns.ChangedColumns;
            if (mods.Count == 0) return;
            FillRealTableSchema(table);
            var writer = new SqlServerCompactColumnWriter(Builder);

            foreach (var col in mods.Where(c => c.DefaultDropped))
            {
                Builder.AppendFormat("alter table {0} alter column {1} drop default;\n", table.Name, col.Name);
            }

            foreach (var col in mods.Where(d => !d.IsDropped))
            {
                Builder.AppendFormat("alter table [{0}] alter column {1} ", table.Name,
                                     SqlServerProvider.EscapeIdentifier(col.Current.Name));
                writer.Write(col);
                Builder.AppendLine(";");
            }

            foreach (var cl in mods.Where(c => !string.IsNullOrEmpty(c.DefaultValue)))
            {
                Builder.AppendFormat("alter table {0} alter column {1} set default '{2}';\n", table.Name, cl.Name,
                                     cl.DefaultValue);
            }
        }
Ejemplo n.º 2
0
 public ConstraintsCollection(TableSchema table)
 {
     _table = table;
     Checks = new List<CheckConstraint>();
     Uniques = new List<UniqueKeyConstraint>();
     ForeignKeys = new List<ForeignKeyConstraint>();
     Dropped = new DroppedSchemaItemsCollection(table.Name);
 }
Ejemplo n.º 3
0
 public override string GenerateCreateTable(TableSchema table)
 {
     if (table.Columns.IsIdentityDefined)
     {
         var pk=table.Constraints.PrimaryKey;
         if (pk!=null) pk.Ignore = true;
     }
     return base.GenerateCreateTable(table);
 }
Ejemplo n.º 4
0
 public CreateTableBuilder(DbConnection db, IGenerateDDL generator, TableSchema schema)
 {
     _db = db;
     _generator = generator;
     _table = schema;
     _columns = new ColumnsCreator(Table);
     _constraints = new ConstraintsCreator(Table.Constraints);
     _indexes = new IndexCreator(Table.Indexes);
 }
Ejemplo n.º 5
0
 public void Process(TableSchema schema)
 {
     _schema = schema;
     _schema.Name = _ti.Name;
     _schema.CreationOption = _ti.CreationOptions;
     ProcessPrimaryKey();
     ProcessColumns();
     ProcessIndexes();
     ProcessForeignKeys();
 }
Ejemplo n.º 6
0
        public ModifyTableBuilder(IAccessDb db, IGenerateDDL generator, string name)
        {
            _db = db;
            _generator = generator;
            name.MustNotBeEmpty();
            _table = new TableSchema(name);

            _columns = new ColumnsEditor(Table, this);
            _constraints = new ConstraintsEditor(Table.Constraints, this);
            _indexes = new IndexEditor(Table.Indexes, this);
        }
Ejemplo n.º 7
0
        public CreateTableBuilder(DbConnection db, IGenerateDDL generator, string tableName, IfTableExists option)
        {
            _db = db;
            _generator = generator;
            tableName.MustNotBeEmpty();
            _table = new TableSchema(tableName);
            _columns = new ColumnsCreator(Table);
            _constraints = new ConstraintsCreator(Table.Constraints);
            _indexes = new IndexCreator(Table.Indexes);

            Table.Name = tableName;
            Table.CreationOption = option;
        }
 private void FillRealTableSchema(TableSchema table)
 {
     var columns = table.ModifiedColumns.AllColumnsNames;
     // var tableName = SqlServerProvider.FormatName(table.Name);
     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)", table.Name, columns);
     foreach (var cs in all)
     {
         var column = table.ModifiedColumns[cs.ColumnName];
         column.Modifications.Current.Type = ExtractType(cs);
         column.Modifications.Current.Collation = cs.CollationName;
     }
 }
Ejemplo n.º 9
0
 public virtual string GenerateCreateTable(TableSchema table)
 {
     _table = table;
     ColonBeforeConstraints = true;
     table.Options.Use(_engine);
     Builder.Clear();
     Builder.Append("create table ");
     WriteTableName();
     Builder.Append(" (");
     WriteColumns(table.Columns);
     WriteConstraints(table.Constraints);
     Builder.Append(")");
     WriteEndTableOptions();
     WriteIndexes(table.Indexes);
     return Builder.ToString();
 }
Ejemplo n.º 10
0
 public IndexCollection(TableSchema table)
 {
     _table  = table;
     Dropped = new DroppedSchemaItemsCollection(table.Name);
 }
Ejemplo n.º 11
0
 public string GenerateCreateTable(TableSchema table)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public string GenerateAlterTable(TableSchema schema)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 public ColumnsCreator(TableSchema table)
 {
     _table = table;
 }
Ejemplo n.º 14
0
 public override string GenerateAlterTable(TableSchema schema)
 {
     throw new NotSupportedException("Sqlite alter table is not supported");
 }
Ejemplo n.º 15
0
 public ColumnsEditor(TableSchema table, IModifyTable parent) : base(table)
 {
     _table  = table;
     _parent = parent;
 }
Ejemplo n.º 16
0
        public virtual string GenerateAlterTable(TableSchema schema)
        {
            _table = schema;
            Builder.Clear();
            DefineExistingColumns();
            WriteColumnRenames();
            WriteDroppedIndexes();
            WriteDroppedConstraints();
            GetChangedColumnsManager().Write(schema.ModifiedColumns);
            WriteDroppedColumns();
            WriteColumnsAdditions();
            WriteConstraintsAdditions();
            WriteIndexes(Table.Indexes);

            return Builder.ToString();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a fluent builder object to help you generate a Create Table script, starting from an existing type.
        /// You can customize it further
        /// </summary>
        /// <returns></returns>
        public ICreateTable GetCreateTableBuilder <T>()
        {
            var schema = new TableSchema(typeof(T));

            return(new CreateTableBuilder(Db, GetDDLWriter(), schema));
        }
Ejemplo n.º 18
0
 public ColumnsCreator(TableSchema table)
 {
     _table = table;
 }