Click here to Skip to main content
15,883,773 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.9K   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 for loading a BLOB field into the local file system
    /// and doing this in a chunky way that won't cause too much memory to be used.
    /// </summary>
    public class BlobLoader : AbstractWorker, IDisposable
    {
        #region Constructors & Destructors
        public BlobLoader(string dbpath, string tableName, string columnName, long rowId, string blobFile)
            : base("BlobLoader")
        {
            _blobReader = new BlobReaderWriter(dbpath, true);
            _tableName = tableName;
            _columnName = columnName;
            _rowId = rowId;
            _blobFile = blobFile;
        }

        ~BlobLoader()
        {
            Dispose(false);
        }
        #endregion

        #region Protected Overrided Methods
        protected override void DoWork()
        {
            // Call the BLOB reader object to do the job
            _blobReader.ReadBlobToFile(_tableName, _columnName, _rowId, _blobFile, ProgressHandler);
        }

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

        #region IDisposable Members

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);     
        }

        #endregion

        #region Protected Virtual Methods
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Release managed resources
                    _blobReader.Dispose();
                }

                // Mark that the object was disposed
                _disposed = true;
            }
        }
        #endregion

        #region Private Methods
        private void ProgressHandler(byte[] buffer, int length, int bytesRead, int totalBytes, ref bool cancel)
        {
            cancel = this.WasCancelled;

            int progress = (int)(100.0 * bytesRead / totalBytes);
            if (progress > _progress)
            {
                NotifyPrimaryProgress(false, progress, Utils.FormatMemSize(bytesRead, MemFormat.KB) + "/" + 
                    Utils.FormatMemSize(totalBytes, MemFormat.KB) + " loaded so far", null);
                _progress = progress;
            }
        }
        #endregion

        #region Private Variables
        private long _rowId;
        private string _blobFile;
        private string _tableName;
        private string _columnName;
        private int _progress = 0;
        private bool _disposed;
        private BlobReaderWriter _blobReader = null;
        #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