Click here to Skip to main content
15,881,172 members
Articles / Desktop Programming / Windows Forms

SQLite Compare Utility

Rate me:
Please Sign up or sign in to vote.
4.89/5 (68 votes)
21 Feb 2015LGPL35 min read 280.1K   37.1K   131  
Utility for comparing two SQLite database files for both structure and data
using System;
using System.Collections.Generic;
using System.Text;

namespace SQLiteTurbo
{
    /// <summary>
    /// This class is responsible to copy rows from one table to another
    /// </summary>
    public class RowsCopier : AbstractWorker
    {
        #region Constructor
        public RowsCopier(TableChanges tchanges, string diff, List<TableChangesRange> rows, bool leftToRight)
            : base("RowsCopier")
        {
            _diff = diff;
            _changes = tchanges;
            _rows = rows;
            _leftToRight = leftToRight;
        }
        #endregion

        #region Protected Overrided Methods
        protected override void DoWork()
        {
            // Ask the table changes object to do the copy
            _changes.CopyRows(_diff, _rows, _leftToRight, RowsCopyingHandler);
        }

        protected override bool IsDualProgress
        {
            get
            {
                return true;
            }
        }
        #endregion

        #region Private Methods
        private void RowsCopyingHandler(int rowsCopied, int totalRows, string blobName, int blobBytesCopied, int totalBlobBytes, ref bool cancel)
        {
            cancel = WasCancelled;

            if (blobName == null)
            {
                if (totalRows > 0)
                {
                    int progress = (int)(100.0 * rowsCopied / totalRows);
                    if (progress > _progress)
                    {
                        NotifyPrimaryProgress(false, progress, rowsCopied.ToString() + "/" + totalRows.ToString() + " copied", null);
                        _progress = progress;
                    }
                }
            }
            else
            {
                if (totalBlobBytes > 0)
                {
                    int progress = (int)(100.0 * blobBytesCopied / totalBlobBytes);
                    bool done = blobBytesCopied == totalBlobBytes;
                    NotifySecondaryProgress(done, progress, Utils.FormatMemSize(blobBytesCopied, MemFormat.KB) + "/" +
                        Utils.FormatMemSize(totalBlobBytes, MemFormat.KB) + " (" + blobName + ")", null);
                }
            } // else
        }
        #endregion

        #region Private Variables
        private string _diff;
        private int _progress;
        private TableChanges _changes;
        private List<TableChangesRange> _rows;
        private bool _leftToRight;
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
Israel Israel
My name is Liron Levi and I'm developing software for fun & profit for 15 years already.

Comments and Discussions