protected void DoGetModificationsCore(string sql, string modifyColumn, string nameColumn, string schemaColumn = null, string idColumn = null) { var existingTables = new HashSet <string>(); using (var cmd = Connection.CreateCommand()) { cmd.CommandText = sql; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { string modify = reader.SafeString(modifyColumn); string name = reader.SafeString(nameColumn); string schema = schemaColumn != null?reader.SafeString(schemaColumn) : null; string objectId = idColumn != null?reader.SafeString(idColumn) : null; existingTables.Add(name); var fullName = new NameWithSchema(schema, name); var obj = Structure.FindTable(fullName); if (obj == null) { var item = new DatabaseChangeItem { Action = DatabaseChangeAction.Add, ObjectType = DatabaseObjectType.Table, ObjectId = objectId ?? CreateObjectId("table", schema, name), NewName = fullName, }; ChangeSet.Items.Add(item); } else { if (obj.ModifyInfo == null || obj.ModifyInfo != modify) { var item = new DatabaseChangeItem { Action = DatabaseChangeAction.Change, ObjectType = DatabaseObjectType.Table, OldName = ((NamedObjectInfo)obj).FullName, NewName = fullName, ObjectId = objectId ?? CreateObjectId("table", schema, name), }; ChangeSet.Items.Add(item); } } } } } if (idColumn != null) { AddDeletedObjectsById(Structure.Tables, existingTables); } else { AddDeletedObjectsByName(Structure.Tables, existingTables, "table"); } }
protected void AddDeletedObjectsById <T>(IEnumerable <T> items, HashSet <string> existingObjects) where T : NamedObjectInfo { foreach (var obj in items) { if (!existingObjects.Contains(obj.ObjectId)) { var item = new DatabaseChangeItem { Action = DatabaseChangeAction.Remove, ObjectId = obj.ObjectId, ObjectType = obj.ObjectType, OldName = obj.FullName, }; ChangeSet.Items.Add(item); } } }
protected void AddDeletedObjectsByName <T>(IEnumerable <T> items, HashSet <string> existingObjects, string objectIdPrefix) where T : NamedObjectInfo { foreach (var obj in items) { if (!existingObjects.Contains(obj.FullName.Name)) { var item = new DatabaseChangeItem { Action = DatabaseChangeAction.Remove, ObjectType = obj.ObjectType, OldName = obj.FullName, ObjectId = CreateObjectId(objectIdPrefix, obj.Schema, obj.Name), }; ChangeSet.Items.Add(item); } } }