private void GetDataFromTable(SyncInfo reportInfo, TableInfo tableInfo, TableMapping tableMap, bool isSource, string tableName) { string sql; string parameterSymbol = isSource ? "?" : "@"; bool firstKey = true; if (isSource && !string.IsNullOrEmpty(tableMap.CustomSourceSQLForSyncOnly)) { sql = tableMap.CustomSourceSQLForSyncOnly; } else { var whereColumns = tableInfo.Columns.Where(c => c.PrimaryKey).Select(c => "(" + c.ColumnName + " = " + parameterSymbol + c.ColumnName + ")"); sql = "select * from " + tableName + " where " + string.Join(" AND ", whereColumns) + ";"; } var query = new SQLQuery(sql); foreach (var column in tableInfo.Columns.Where(c => c.PrimaryKey).OrderBy(c => c.ColumnID)) { if (sql.Contains(parameterSymbol + column.ColumnName)) { query.Parameters.Add(column.ColumnName, firstKey ? reportInfo.PrimaryKey1 : reportInfo.PrimaryKey2); } firstKey = false; } if (isSource) { query.ProcessRow = reader => { for (int i = 0; i < reader.FieldCount; i++) { reportInfo.SourceDataList.Insert(i, ConvertDataTypes(reader[i])); } return false; }; sourceDB.RunQuery(query); } else { query.ProcessRow = reader => { for (int i = 0; i < reader.FieldCount; i++) { reportInfo.DestinationDataList.Insert(i, ConvertDataTypes(reader[i])); } return false; }; destinationDB.RunQuery(query); } }
private void CompareRowCounts(TableMapping tableMap, StringBuilder differences) { var sourceCount = sourceDB.RunScalerQuery<string>(CountSql + tableMap.FullyQualifiedSourceTable); var destinationCount = destinationDB.RunScalerQuery<string>(CountSql + tableMap.FullyQualifiedDestinationTable); if (Convert.ToInt32(sourceCount) != Convert.ToInt32(destinationCount)) { differences.Append(string.Format("\t-[{0}].[{1}] : {2}\n\t [{3}].[{4}] : {5}\n\n", tableMap.SourceSchema, tableMap.SourceTable, sourceCount, tableMap.DestinationSchema, tableMap.DestinationTable, destinationCount)); } }