Click here to Skip to main content
15,896,207 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.5K   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 SQLiteFromClause
    {
        public SQLiteFromClause AddJoin(SQLiteJoinOperator join)
        {
            _tables.Add(join);
            return this;
        }

        public SQLiteFromClause AddTable(SQLiteObjectName tableName, string asName, 
            SQLiteFromIndexed indexed, SQLiteExpression onExpr, List<string> usingOpt)
        {
            _tables.Add(new SQLiteFromTable(tableName, asName, indexed, onExpr, usingOpt));
            return this;
        }

        public SQLiteFromClause AddInternalTable(SQLiteFromInternalTable itable, string asName,
            SQLiteExpression onExpr, List<string> usingOpt)
        {
            _tables.Add(new SQLiteFromTable(itable, asName, onExpr, usingOpt));
            return this;
        }

        public List<object> FromTables
        {
            get { return _tables; }
        }

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

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

            if (!RefCompare.CompareList<object>(_tables, dst._tables))
                return false;

            return true;
        }

        public override string ToString()
        {
            if (_tables == null || _tables.Count == 0)
                return string.Empty;

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < _tables.Count; i++)
            {
                if (_tables[i] is SQLiteFromTable)
                    sb.Append(_tables[i].ToString());
                else
                    sb.Append(Utils.GetJoinOperatorString((SQLiteJoinOperator)_tables[i]));
                if (i < _tables.Count - 1)
                    sb.Append(" ");
            } // for
            return sb.ToString();
        }

        public virtual object Clone()
        {
            List<object> tlist = null;
            if (_tables != null)
            {
                tlist = new List<object>();
                foreach (object obj in _tables)
                {
                    if (obj is SQLiteFromTable)
                    {
                        SQLiteFromTable ft = (SQLiteFromTable)obj;
                        tlist.Add(ft.Clone());
                    }
                    else if (obj is SQLiteJoinOperator)
                        tlist.Add(obj);
                } // foreach
            }

            SQLiteFromClause res = new SQLiteFromClause();
            res._tables = tlist;
            return res;
        }

        private List<object> _tables = new List<object>();
    }
}

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