Exemple #1
0
        private ComparerResult GetTriggersDiff()
        {
            ComparerResult result = new ComparerResult();

            CompareObjects <Trigger>(_conSrc, _conDst, ObjectType.Trigger, GetTriggers, result.DiffsInSrc);
            CompareObjects <Trigger>(_conDst, _conSrc, ObjectType.Trigger, GetTriggers, result.DiffsInDst);
            return(result);
        }
Exemple #2
0
        private ComparerResult GetUniqueKeysDiff()
        {
            ComparerResult result = new ComparerResult();

            CompareObjects <UniqueKey>(_conSrc, _conDst, ObjectType.UniqueKey, GetUniqueKeys, result.DiffsInSrc);
            CompareObjects <UniqueKey>(_conDst, _conSrc, ObjectType.UniqueKey, GetUniqueKeys, result.DiffsInDst);
            return(result);
        }
Exemple #3
0
        private ComparerResult GetStoredFunctionsDiff()
        {
            ComparerResult result = new ComparerResult();

            CompareObjects <StoredFunction>(_conSrc, _conDst, ObjectType.StoredFunction, GetFunctions, result.DiffsInSrc);
            CompareObjects <StoredFunction>(_conDst, _conSrc, ObjectType.StoredFunction, GetFunctions, result.DiffsInDst);
            return(result);
        }
Exemple #4
0
        private ComparerResult GetStoredProceduresDiff()
        {
            ComparerResult result = new ComparerResult();

            CompareObjects <StoredProcedure>(_conSrc, _conDst, ObjectType.StoredProcedure, GetProcedures, result.DiffsInSrc);
            CompareObjects <StoredProcedure>(_conDst, _conSrc, ObjectType.StoredProcedure, GetProcedures, result.DiffsInDst);
            return(result);
        }
Exemple #5
0
        private ComparerResult GetViewsDiff()
        {
            ComparerResult result = new ComparerResult();

            CompareObjects <View>(_conSrc, _conDst, ObjectType.View, GetViews, result.DiffsInSrc);
            CompareObjects <View>(_conDst, _conSrc, ObjectType.View, GetViews, result.DiffsInDst);
            return(result);
        }
Exemple #6
0
        private ComparerResult GetTableDiff()
        {
            ComparerResult result = new ComparerResult();

            CompareObjects <Column>(_conSrc, _conDst, ObjectType.Column, GetColumns, result.DiffsInSrc);
            CompareObjects <Column>(_conDst, _conSrc, ObjectType.Column, GetColumns, result.DiffsInDst);
            return(result);
        }
Exemple #7
0
        private void SchemaComparerForm_Load(object sender, EventArgs e)
        {
            DataTable tbl = new DataTable();

            // Left Script, Item (db1.Custmers, Table), Status, Right Script
            tbl.Columns.Add("Left Script", typeof(string));
            tbl.Columns.Add("Item", typeof(string));
            tbl.Columns.Add("Status", typeof(string));
            tbl.Columns.Add("Right Script", typeof(string));

            // Populate table:
            EnsureConnectionsOpened();
            cmp    = new Comparer(SourceConnection, DestinyConnection);
            result = cmp.Compare();

            foreach (ComparerResultItem cri in result.DiffsInSrc)
            {
                DataRow dr = tbl.NewRow();
                dr["Left Script"]  = cri.MtObject.GetScript(cri.Type);
                dr["Item"]         = cri.MtObject.FullName;
                dr["Status"]       = cri.Type.ToString();
                dr["Right Script"] = "";
                tbl.Rows.Add(dr);
            }

            foreach (ComparerResultItem cri in result.DiffsInDst)
            {
                DataRow dr = tbl.NewRow();
                dr["Left Script"]  = "";
                dr["Item"]         = cri.MtObject.FullName;
                dr["Status"]       = cri.Type.ToString();
                dr["Right Script"] = cri.MtObject.GetScript(cri.Type);
                tbl.Rows.Add(dr);
            }

            // Populate results back to grid
            dgDiffSummary.DataSource = tbl;
            foreach (DataGridViewRow row in dgDiffSummary.Rows)
            {
                //if ( ((string)row.Cells[0].Value == "") && (( string )row.Cells[ 3 ].Value != "" ))
                //{
                //  // differences in right side
                //  row.DefaultCellStyle.BackColor = Color.Red;
                //}
            }
        }
Exemple #8
0
        /// <summary>
        /// Compares database from source connection with database from destiny connection.
        /// </summary>
        internal ComparerResult Compare()
        {
            /*
             * - Iterate over all source items and look for them in destiny.
             * - Iterate over all destiny items and look for them in source.
             * - Look for missing items (will emit create).
             * - Look for different items (will emit drop/create or alter).
             * - Look for extra items (will emit drop).
             */
            ComparerResult result = new ComparerResult();
            // Get Tables
            ComparerResult resTmp = GetTableDiff();

            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Primary keys
            resTmp = GetPrimaryKeysDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Unique keys
            resTmp = GetUniqueKeysDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Foreign keys
            resTmp = GetForeignKeysDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Views
            resTmp = GetViewsDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Procedures
            resTmp = GetStoredProceduresDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Functions
            resTmp = GetStoredFunctionsDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            // Get Triggers
            resTmp = GetTriggersDiff();
            result.DiffsInDst.AddRange(resTmp.DiffsInDst);
            result.DiffsInSrc.AddRange(resTmp.DiffsInSrc);
            return(result);
        }
Exemple #9
0
        internal void GetScript(ComparerResult result, bool isSource, out string scriptSrc, out string scriptDst)
        {
            List <ComparerResultItem> src   = null;
            List <ComparerResultItem> dst   = null;
            StringBuilder             sbDst = new StringBuilder();
            StringBuilder             sbSrc = new StringBuilder();

            if (isSource)
            {
                src = result.DiffsInSrc;
                dst = result.DiffsInDst;
            }
            else
            {
                src = result.DiffsInDst;
                dst = result.DiffsInSrc;
            }
            sbSrc.AppendLine("delimiter // ");
            for (int i = 0; i < src.Count; i++)
            {
                if (src[i].Type != ComparerResultItemType.Extra)
                {
                    sbSrc.Append(src[i].GetScript()).AppendLine(" // ");
                }
            }
            sbDst.AppendLine("delimiter // ");
            for (int i = 0; i < dst.Count; i++)
            {
                if (dst[i].Type == ComparerResultItemType.Extra)
                {
                    sbDst.Append(dst[i].GetScript()).AppendLine(" // ");
                }
            }
            scriptDst = sbDst.ToString();
            scriptSrc = sbSrc.ToString();
        }