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;
using System.Data.SQLite;
using System.IO;

namespace CreateTestDatabases
{
    public class CreateDataChecks_2 : IDatabasePairCreator
    {
        #region IDatabasePairCreator Members

        public void CreatePair(string db1, string db2)
        {
            if (File.Exists(db1))
                File.Delete(db1);
            if (File.Exists(db2))
                File.Delete(db2);
            SQLiteConnection.CreateFile(db1);

            using (SQLiteConnection c1 = Utils.CreateConnection(db1))
            {
                c1.Open();

                Utils.RunCommand(
                    @" CREATE TABLE test1 " +
                    @" (" +
                    @"    ascending integer NOT NULL PRIMARY KEY," +
                    @"    t1 char," +
                    @"    t2 char(10),"+
                    @"    t3 varchar,"+
                    @"    t4 varchar(50),"+
                    @"    t5 nchar,"+
                    @"    t6 nchar(10),"+
                    @"    t7 text,"+
                    @"    t8 tinytext,"+
                    @"    t9 mediumtext,"+
                    @"    t10 longtext"+
                    @" )", c1);

                SQLiteTransaction tx1 = c1.BeginTransaction();
                InsertData(c1, tx1);
                tx1.Commit();

                File.Copy(db1, db2);
            } // using
        }

        #endregion

        private void InsertData(SQLiteConnection conn, SQLiteTransaction tx)
        {
            Random rand = new Random();
            SQLiteCommand insert = new SQLiteCommand("INSERT INTO test1 " +
                "(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) VALUES " +
                "('a','b','c','d','e','f','e','g','h','i')", conn, tx);

            for (int i = 0; i < 100; i++)
            {
                insert.ExecuteNonQuery();
            } // for
        }
    }
}

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