Click here to Skip to main content
15,881,793 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;

namespace Be.Windows.Forms
{
    internal sealed class FileDataBlock : DataBlock
    {
        long _length;
        long _fileOffset;

        public FileDataBlock(long fileOffset, long length)
        {
            _fileOffset = fileOffset;
            _length = length;
        }

        public long FileOffset
        {
            get
            {
                return _fileOffset;
            }
        }

        public override long Length
        {
            get
            {
                return _length;
            }
        }

        public void SetFileOffset(long value)
        {
            _fileOffset = value;
        }

        public void RemoveBytesFromEnd(long count)
        {
            if (count > _length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            _length -= count;
        }

        public void RemoveBytesFromStart(long count)
        {
            if (count > _length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            _fileOffset += count;
            _length -= count;
        }

        public override void RemoveBytes(long position, long count)
        {
            if (position > _length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            if (position + count > _length)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            long prefixLength = position;
            long prefixFileOffset = _fileOffset;

            long suffixLength = _length - count - prefixLength;
            long suffixFileOffset = _fileOffset + position + count;

            if (prefixLength > 0 && suffixLength > 0)
            {
                _fileOffset = prefixFileOffset;
                _length = prefixLength;
                _map.AddAfter(this, new FileDataBlock(suffixFileOffset, suffixLength));
                return;
            }

            if (prefixLength > 0)
            {
                _fileOffset = prefixFileOffset;
                _length = prefixLength;
            }
            else
            {
                _fileOffset = suffixFileOffset;
                _length = suffixLength;
            }
        }
    }
}

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