/// <summary> /// Compares the table definitions for two tables. /// </summary> /// <param name="sourceTable"></param> /// <param name="destinationTable"></param> private void FilterMatches(TableDescriptor sourceTable, TableDescriptor destinationTable) { // Filter definitions so they only contain the differences DataTableComparer.FilterMatches(sourceTable.ColumnDefinition, destinationTable.ColumnDefinition, new string[] { "COLUMN_NAME" }, new string[] { "TABLE_CATALOG", "ORDINAL_POSITION" }); DataTableComparer.FilterMatches(sourceTable.ConstraintDefinition, destinationTable.ConstraintDefinition, new string[] { "CONSTRAINT_NAME" }, new string[] { "CONSTRAINT_CATALOG", "TABLE_CATALOG" }); DataTableComparer.FilterMatches(sourceTable.ForeignKeyDefinition, destinationTable.ForeignKeyDefinition, new string[] { "FOREIGN_KEY_NAME" }, null); DataTableComparer.FilterMatches(sourceTable.IndexDefinition, destinationTable.IndexDefinition, new string[] { "INDEX_NAME", "COLUMN_NAME" }, new string[] { "TABLE_CATALOG", "INDEX_CATALOG", "CARDINALITY", "PAGES" }); DataTableComparer.FilterMatches(sourceTable.TableInfoDefinition, destinationTable.TableInfoDefinition, new string[] { "TABLE_NAME" }, new string[] { "TABLE_CATALOG", "TABLE_VERSION", "CARDINALITY" }); DataTableComparer.FilterMatches(sourceTable.TableDefinition, destinationTable.TableDefinition, new string[] { "TABLE_NAME" }, new string[] { "TABLE_CATALOG", "DATE_CREATED", "DATE_MODIFIED" }); }
internal TableComparison(string tablename, TableDescriptor sourceTable, TableDescriptor destinationTable) { _tablename = tablename; _sourceTable = sourceTable; _destinationTable = destinationTable; }
/// <summary> /// Compares all the supplied table definitions. /// </summary> /// <param name="sourceTables"></param> /// <param name="destinationTables"></param> private void CompareAllTables(DataTable sourceTables, DataTable destinationTables, DatabaseComparison comparison) { // Verify source tables foreach(DataRow row in sourceTables.Rows) { // Fetch information about source table string tabname = (string)row["TABLE_NAME"]; Debug.WriteLine("Retrieving table information for " + tabname); DataSet ds = _sourceDbService.GetTableInfo(tabname); TableDescriptor sourceTable = new TableDescriptor(ds); // Lookup destination table TableComparison tablecomparison; DataRow[] desttabs = destinationTables.Select(string.Format("TABLE_NAME='{0}'", tabname)); if(desttabs.Length > 0) { // Table exists in destination, retrieve more info and compare them ds = _destinationDbService.GetTableInfo(tabname); TableDescriptor destinationTable = new TableDescriptor(ds); FilterMatches(sourceTable, destinationTable); // Create comparison result tablecomparison = new TableComparison(tabname, sourceTable, destinationTable); } else { // Create comparison result (destination table is missing) tablecomparison = new TableComparison(tabname, sourceTable, null); } // Add comparison result and fire event comparison.TableComparisons.Add(tablecomparison); EventManager.OnTableComparisonComplete(tablecomparison); } }