コード例 #1
0
ファイル: SyncStatusReport.cs プロジェクト: seatre/DbSync
        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);
            }
        }
コード例 #2
0
ファイル: SyncStatusReport.cs プロジェクト: seatre/DbSync
        private void CheckData(SyncInfo syncChangeData, StringBuilder differences, string failedMessage)
        {
            if (syncChangeData.DestinationDataList.Count() > syncChangeData.SourceDataList.Count())
            {
                differences.Append("\n\t-Delete " + failedMessage);
            }
            else if (syncChangeData.DestinationDataList.Count() < syncChangeData.SourceDataList.Count())
            {
                differences.Append("\n\t-Insert " + failedMessage);
            }
            else if (syncChangeData.DestinationDataList.Count() == syncChangeData.SourceDataList.Count() &&
                     syncChangeData.SourceDataList.Count() != 0)
            {
                for (int i = 0; i < syncChangeData.DestinationDataList.Count(); i++)
                {
                    if (ConvertBoolToStringInt(syncChangeData.DestinationDataList[i].ToString().Trim()) != ConvertBoolToStringInt(syncChangeData.SourceDataList[i].ToString().Trim()))
                    {
                        differences.Append(
                            string.Format("\n\t-Column mismatch. Source Table: {0}, PK: {1}, Destination Value:{2}, Source Value:{3}",
                                syncChangeData.SourceSchemaName + "." + syncChangeData.SourceTableName, syncChangeData.PrimaryKey1, syncChangeData.DestinationDataList[i], syncChangeData.SourceDataList[i]));
                    }
                }

            }
        }