コード例 #1
0
ファイル: MatchedDatabase.cs プロジェクト: fjiang2/sqlcon
        public static TableName[] Search(string pattern, TableName[] tableNames)
        {
            Regex regex = pattern.WildcardRegex();
            var result = tableNames.Where(tname => regex.IsMatch(tname.Name)).ToArray();

            return result;
        }
コード例 #2
0
ファイル: CompareAdapter.cs プロジェクト: fjiang2/sqlcon
        public string Run(ActionType compareType, TableName[] N1, TableName[] N2, Configuration cfg, string[] exceptColumns)
        {
            DatabaseName dname1 = Side1.DatabaseName;
            DatabaseName dname2 = Side2.DatabaseName;

            stdio.WriteLine("server1: {0} default database:{1}", Side1.Provider.DataSource, dname1.Name);
            stdio.WriteLine("server2: {0} default database:{1}", Side2.Provider.DataSource, dname2.Name);

            if (!Exists(dname1) || !Exists(dname2))
                return string.Empty;

            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("-- sqlcon:", Side1.Provider.DataSource, dname1.Name).AppendLine();
            builder.AppendFormat("-- compare server={0} db={1}", Side1.Provider.DataSource, dname1.Name).AppendLine();
            builder.AppendFormat("--         server={0} db={1} @ {2}", Side2.Provider.DataSource, dname2.Name, DateTime.Now).AppendLine();

            CancelableWork.CanCancel(cts =>
            {
                foreach (var tname1 in N1)
                {
                    if (cts.IsCancellationRequested)
                        return;

                    TableName tname2 = N2.Where(t => t.ShortName == tname1.ShortName).FirstOrDefault();
                    if (tname2 == null)
                    {
                        tname2 = new TableName(dname2, tname1.SchemaName, tname1.ShortName);
                    }

                    if (compareType == ActionType.CompareData && cfg.compareExcludedTables.FirstOrDefault(t => t == tname1.Name) != null)
                    {
                        stdio.WriteLine("{0} is excluded", tname1);
                        continue;
                    }

                    if (tname2.Exists())
                        builder.Append(CompareTable(compareType, CompareSideType.compare, tname1, tname2, cfg.PK, exceptColumns));
                    else
                    {
                        if (compareType == ActionType.CompareSchema)
                        {
                            string sql = tname1.GenerateCluase();
                            stdio.WriteLine(sql);
                            builder.Append(sql);
                        }
                        else
                        {
                            stdio.WriteLine("{0} doesn't exist", tname2);
                        }
                    }
                }

            });

            return builder.ToString();
        }