Comments
2 comments
-
A major part of the work for SQL Data Compare engine for version 5 was 'cleaning up' a lot of the API and integration with the SQL Compare engine for schema information. What this means is that applications that used the old API will need to be adapted to work with the version 5 API. Hopefully this should solve a lot of the complexities that existed in the previous API and make applications a lot quicker to develop.
As you have noted one of the main changes is that TableComparisonSettings has been removed, this has been replaced with the Mappings classes. These give SQL Data Compare a lot of its power to compare databases with different schema information. Also of note is the new organisation of results stores - it used to be a set of up to 4 results stores per table difference these are now combined into one result store difference.ResultsStore you can still access the individual parts of the results store although I wouldn't recommend it.
Here I include one of our example texts so you can see what is going on in the new API hopefully it will give you an idea of what to do...using RedGate.SQL.Shared; using RedGate.SQLCompare.Engine; using RedGate.SQLDataCompare.Engine; namespace Example { public class Example { public static void Main() { Database db1=new Database(); Database db2=new Database(); ComparisonSession session=new ComparisonSession(); TableMappings mappings = new TableMappings(); try { db1.RegisterForDataCompare(new ConnectionProperties(".", "WidgetDev")); db2.RegisterForDataCompare(new ConnectionProperties(".", "WidgetLive")); mappings.CreateMappings(db1.Tables, db2.Tables); // Create the mappings between the two databases session.CompareDatabases(db1, db2, mappings); foreach (TableMapping mapping in mappings) { if (mapping.Status == MappingStatus.Success) // Make sure that this is a valid mapping { ViewTableSuperClass table = mapping.Obj1; TableDifference difference=session.TableDifferences[table.FullyQualifiedName]; //display the different records using (Reader different=difference.ResultsStore.GetReader()) { foreach(Row row in difference.ResultsStore) //loop through all the rows { if (row.Type != Row.RowType.Same) //go through the non same records { Console.WriteLine("{0} Row {1} type {2}", table.FullyQualifiedName, row.Index, row.Type.ToString()); foreach (FieldPair field in different.Fields) { //work out where about in the results the field data is stored //if we were comparing identical records, or records present in one //database but not the other then we would not need to //use the OrdinalInResults1 and OrdinalInResults2 properties //but just OrdinalInResults int field1=field.OrdinalInResults1; int field2=field.OrdinalInResults2; if (field1 != field2) { //get the values object value1=row.Values[field1]; object value2=row.Values[field2]; if (value1 == null) value1="NULL"; if (value2 == null) value2="NULL"; Console.WriteLine("{0}\t{1}\t{2}\t{3}",field.Field(false).Name, value1.ToString(),Store.IdenticalValues(value1, value2, field)?"==":"<>", value2.ToString()); } else { //this is part of the unique index we are comparing on object value=row.Values[field1]; Console.WriteLine("*{0}\t{1}",field.Field(false).Name, value.ToString()); } }//End of foreach field pair } }//End of foreach row }//End of using reader }//End of mapping status }//End of foreach mapings } finally { //dispose of the object session.Dispose(); db1.Dispose(); db2.Dispose(); } } } }
Note: There is also a new feature on the ResultsStore.Row object to determine if two fields on a row are different very quickly this is the FieldDifferent() method.
Hope this helps initially. -
Thanks, Richard. I'll check it out.
Fleming
Add comment
Please sign in to leave a comment.
I'm walking through the API samples and I'm getting a compile error.
Error 7 The type or namespace name 'TableComparisonSettings' could not be found (are you missing a using directive or an assembly reference?)
I have the following usings
using RedGate.SQL.Shared;
using RedGate.SQLCompare.Engine;
using RedGate.SQLDataCompare.Engine;
using RedGate.SQLDataCompare.Engine.ResultsStore;
What have I missed?
Thanks.
fleming