Beispiel #1
0
        protected bool GetDatabaseDiff(Database db1, Database db2, string[] options, TextWriter diffOutput, string linePrefix, IDiffEngineFactory diffFactory)
        {
            bool difference = false;

            string tempFile = Path.GetTempFileName();
            if(db2.GenerateTransform(db1, tempFile))
            {
                difference = true;

                Database db = db1;
                db.ViewTransform(tempFile);

                string row, column, change;
                using (View view = db.OpenView("SELECT `Table`, `Column`, `Row`, `Data`, `Current` " +
                    "FROM `_TransformView` ORDER BY `Table`, `Row`"))
                {
                    view.Execute();

                    foreach (Record rec in view) using (rec)
                    {
                        column = String.Format("{0} {1}", rec[1], rec[2]);
                        change = "";
                        if (rec.IsNull(3))
                        {
                            row = "<DDL>";
                            if (!rec.IsNull(4))
                            {
                                change = "[" + rec[5] + "]: " + DecodeColDef(rec.GetInteger(4));
                            }
                        }
                        else
                        {
                            row = "[" + String.Join(",", rec.GetString(3).Split('\t')) + "]";
                            if (rec.GetString(2) != "INSERT" && rec.GetString(2) != "DELETE")
                            {
                                column = String.Format("{0}.{1}", rec[1], rec[2]);
                                change = "{" + rec[5] + "}->{" + rec[4] + "}";
                            }
                        }

                        diffOutput.WriteLine("{0}{1,-25} {2} {3}", linePrefix, column, row, change);
                    }
                }
            }
            File.Delete(tempFile);

            return difference;
        }