Click here to Skip to main content
15,881,715 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 MemoryDataBlock : DataBlock
    {
        byte[] _data;

        public MemoryDataBlock(byte data)
        {
            _data = new byte[] { data };
        }

        public MemoryDataBlock(byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            _data = (byte[])data.Clone();
        }

        public override long Length
        {
            get
            {
                return _data.LongLength;
            }
        }

        public byte[] Data
        {
            get
            {
                return _data;
            }
        }

        public void AddByteToEnd(byte value)
        {
            byte[] newData = new byte[_data.LongLength + 1];
            _data.CopyTo(newData, 0);
            newData[newData.LongLength - 1] = value;
            _data = newData;
        }

        public void AddByteToStart(byte value)
        {
            byte[] newData = new byte[_data.LongLength + 1];
            newData[0] = value;
            _data.CopyTo(newData, 1);
            _data = newData;
        }

        public void InsertBytes(long position, byte[] data)
        {
            byte[] newData = new byte[_data.LongLength + data.LongLength];
            if (position > 0)
            {
                Array.Copy(_data, 0, newData, 0, position);
            }
            Array.Copy(data, 0, newData, position, data.LongLength);
            if (position < _data.LongLength)
            {
                Array.Copy(_data, position, newData, position + data.LongLength, _data.LongLength - position);
            }
            _data = newData;
        }

        public override void RemoveBytes(long position, long count)
        {
            byte[] newData = new byte[_data.LongLength - count];

            if (position > 0)
            {
                Array.Copy(_data, 0, newData, 0, position);
            }
            if (position + count < _data.LongLength)
            {
                Array.Copy(_data, position + count, newData, position, newData.LongLength - position);
            }

            _data = newData;
        }
    }
}

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