Click here to Skip to main content
15,881,600 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.2K   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 SQLiteParser
{
    public class SQLiteLikeExpression : SQLiteExpression
    {
        private SQLiteLikeExpression()
        {
        }

        public SQLiteLikeExpression(SQLiteExpression left, SQLiteLikeOperator likeOp, SQLiteExpression right, SQLiteExpression escape)
        {
            _left = left;
            _likeOp = likeOp;
            _right = right;
            _escape = escape;
        }

        public SQLiteExpression LeftExpression
        {
            get { return _left; }
            set { _left = value; }
        }

        public SQLiteLikeOperator LikeOperator
        {
            get { return _likeOp; }
            set { _likeOp = value; }
        }

        public SQLiteExpression RightExpression
        {
            get { return _right; }
            set { _right = value; }
        }

        public SQLiteExpression EscapeExpression
        {
            get { return _escape; }
            set { _escape = value; }
        }

        public override bool IsConstant(bool allowNull)
        {
            return false;
        }

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

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

            if (!RefCompare.CompareMany(_likeOp, dst._likeOp, _left, dst._left, _right, dst._right, _escape, dst._escape))
                return false;

            return base.Equals(obj);
        }

        public override string ToString()
        {
            // expr likeop expr escape

            StringBuilder sb = new StringBuilder();
            sb.Append(_left.ToString() + " " + _likeOp.ToString() + " " + _right.ToString());
            if (_escape != null)
                sb.Append(" ESCAPE " + _escape.ToString());

            return sb.ToString();
        }

        public override object Clone()
        {
            SQLiteLikeOperator likeOp = null;
            if (_likeOp != null)
                likeOp = (SQLiteLikeOperator)_likeOp.Clone();
            SQLiteExpression left = null;
            if (_left != null)
                left = (SQLiteExpression)_left.Clone();
            SQLiteExpression right = null;
            if (_right != null)
                right = (SQLiteExpression)_right.Clone();
            SQLiteExpression escape = null;
            if (_escape != null)
                escape = (SQLiteExpression)_escape.Clone();

            SQLiteLikeExpression res = new SQLiteLikeExpression();
            res._likeOp = likeOp;
            res._left = left;
            res._right = right;
            res._escape = escape;
            return res;
        }

        private SQLiteLikeOperator _likeOp;
        private SQLiteExpression _left;
        private SQLiteExpression _right;
        private SQLiteExpression _escape;
    }
}

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