public static void RemoveNonPk1AutoIncrements(TableStructure table, IProgressInfo progress) { IPrimaryKey pk = table.FindConstraint <IPrimaryKey>(); foreach (ColumnStructure col in table.Columns) { var type = col.DataType; if (type is DbTypeInt && ((DbTypeInt)type).Autoincrement) { if (pk == null || pk.Columns.Count != 1 || pk.Columns[0].ColumnName != col.ColumnName) { type.SetAutoincrement(false); progress.LogMessage("migrate", LogLevel.Warning, "Removed autoincrement flag, column {0}.{1} is not primary key", table.FullName, col.ColumnName); } } } }
private ITableStructure CreateTargetStructure() { TableStructure table = new TableStructure(); foreach (DataGridViewRow row in lbtarget.Rows) { var type = GetExprType(row); if (type == null) { continue; } if (type is GenericTransform.ColumnColExprType) { string oldcol = row.Cells[2].Value.ToString(); if (m_srcformat.Columns.GetIndex(oldcol) < 0) { throw new IncorrectObjectReferenceError("DAE-00185", "s_column", oldcol); } var coldef = new ColumnStructure(m_srcformat.Columns[oldcol]); coldef.ColumnName = row.Cells[0].Value.ToString(); table.AddColumn(coldef, true); } else if (type is GenericTransform.RowNumberColExprType) { var col = new ColumnStructure(); col.ColumnName = row.Cells[0].Value.ToString(); col.DataType = new DbTypeInt(); table._Columns.Add(col); if (table.FindConstraint <IPrimaryKey>() == null && table.FindAutoIncrementColumn() == null) { var pk = new PrimaryKey(); pk.Columns.Add(new ColumnReference(col.ColumnName)); table._Constraints.Add(pk); } } else { var col = new ColumnStructure(); col.ColumnName = row.Cells[0].Value.ToString(); col.DataType = new DbTypeString(250); table._Columns.Add(col); } } return(table); }