Click here to Skip to main content
15,896,063 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 285.4K   37.2K   131  
Utility for comparing two SQLite database files for both structure and data
using System;
using System.Collections.Generic;
using System.Text;

namespace SQLiteParser
{
    public class SQLiteCheckTableConstraint : SQLiteTableConstraint
    {
        private SQLiteCheckTableConstraint(string name)
            : base(name)
        {
        }

        public SQLiteCheckTableConstraint(string name, SQLiteExpression expr, SQLiteResolveAction conf)
            : base(name)
        {
            _expr = expr;
            _conf = conf;
        }

        public SQLiteExpression Expression
        {
            get { return _expr; }
            set { _expr = value; }
        }

        public SQLiteResolveAction ResolveAction
        {
            get { return _conf; }
            set { _conf = value; }
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            SQLiteCheckTableConstraint dst = obj as SQLiteCheckTableConstraint;
            if (dst == null)
                return false;

            if (!RefCompare.CompareMany(_expr, dst._expr, _conf, dst._conf))
                return false;

            return base.Equals(obj);
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if (ConstraintName != null)
                sb.Append("CONSTRAINT " + ConstraintName+ " ");
            sb.Append("CHECK (" + _expr.ToString() + ")");
            if (_conf != SQLiteResolveAction.None)
                sb.Append(" " + Utils.GetConflictClauseString(_conf));
            return sb.ToString();
        }

        public override object Clone()
        {
            SQLiteExpression expr = null;
            if (_expr != null)
                expr = (SQLiteExpression)_expr.Clone();

            SQLiteCheckTableConstraint res = new SQLiteCheckTableConstraint(this.ConstraintName);
            res._expr = expr;
            res._conf = _conf;
            return res;
        }

        private SQLiteExpression _expr;
        private SQLiteResolveAction _conf;
    }
}

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