Click here to Skip to main content
15,746,201 members
Articles / Desktop Programming / Windows Forms
Posted 3 Jul 2011


131 bookmarked

SQLite Compare Utility

Rate me:
Please Sign up or sign in to vote.
4.89/5 (68 votes)
21 Feb 2015LGPL35 min read
Utility for comparing two SQLite database files for both structure and data

SQLite Compare Screenshot


SQLite Compare is a small and fast utility that can compare two SQLite database files for schema and data differences.

It was born out of my frustration of finding a decent DB comparison tool for SQLite database files.

Initially, I tried to sell it as a commercial product. After some time, I realized that this is not the course I'd like to pursue and thus I've decided to release it as open source to the SQLite community.

I hope it will be useful for your purposes.

Using the Code

The SQLite Compare utility is composed of the following C# projects:

  • SQLiteParser project - Responsible to parse SQLite SQL schema text and produce an abstract syntax tree of the entire database schema. This is mandatory if we want to be able to compare the schema differences of two different SQLite databases.
  • DiffControl project - Contains a Windows-Forms DIFF control that I've developed so that I can provide the user with the ability to view differences in SQL schema between two SQLite databases and to modify these schemas. It can be useful in other contexts as well so it merited a project of its own. The control itself was written by me, but the diff engine itself was taken from another project in CodeProject.
  • FastGrid project - During the development of the data differences view, I came to the conclusion that the standard C# data grid view control does not have the ability to work with millions of rows. Even when working in VirtualMode, it stores tons of information in memory which makes it impractical for displaying large amounts of information. For this purpose, I developed a very lightweight control (WindowsForms) that can support this fast enough.
  • Liron.Windows.Forms project - Contains the multi-panel control I've developed. I wrote a separate article about this in CodeProject (search for multi panel). Basically - it provides the ability to author multiple pages in a single design time control (like working with a tab control, but without the tabs...)
  • AutomaticUpdates - This project was responsible to check if there is a newer software version in the web site and download it if necessary. It is now obsolete, but a quick reading of the code can reveal what I did and may be useful to you if you intend to support live updates in your application.
  • UndoRedo - A small library I wrote to support UNDO/REDO operations. May be useful in other applications as well.
  • Be.Windows.Forms.HexBox - A very nice control I've downloaded from the internet which supports Hex editing. I used it for editing BLOB field values.
  • SQLiteTurbo - the main application code. All the various forms are here.
  • Misc libraries I've downloaded from open source authors: Garden Point Parser Generator SDK (used to build the SQLite parser code), Log4NET (logging), Puzzle Syntax Box (displaying change scripts)

Since I don't have much time and the code is reasonably documented, I've decided to skip on the explanations of the utility's internal structure and jump right into the instructions of how to use it.

Basically - in order to compare two SQLite database files, you need to click the "Compare..." button. This will open up the "Comparison Details" dialog in which you'll fill in the paths to both SQLite database files and choose the comparison mode:

  • Compare schema only- For comparing only SQL schema differences. This will perform very quickly but will not compare any data.
  • Compare schema and data - For comparing both SQL schema differences and all table data rows. Depending on the databases - this can be a lengthy operation..

Once the comparison is completed - the utility will display a table with all the differences that were found and allow the user to drill down and show the specific differences:

SQLite Comparison Results

When drilling down to a specific DB object, we'll get the detailed difference. For example:

Table Difference Results

At this point, you can copy differences between the two databases and the utility will automatically update the relevant database schema.

In case you need to compare the data rows of the two tables - you can click the "Compare data" button and you'll get the following tab:

Table Difference Results

This tab provides you with the ability to view the data differences between the rows and to copy differences from one table to the other.

Points of Interest

The Gardens Point Parser Generator project proved invaluable resource when building the SQLite parser. In my opinion, it's one of the best SDKs in C# for building parsers and lexical analyzers.

FastGrid and DiffControl projects were very fun to develop. They proved that it is not too difficult to build even complex seeming controls in a short amount of time and are a testament to the fantastic work done by Microsoft and the open source community. Specifically - the Diff engine algorithm was contributed by another CodeProject member.

The SQLite database libraries and the .NET provider are amazingly versatile and robust pieces of code. The work done by Dr. Richard Hipp (SQLite C libraries) and Robert Simpson (C# SQLite Provider) is simply fantastic!

IMPORTANT NOTE: Due to the way the .net sqlite provider works - comparison will not work correctly for GUID type columns. Note that GUID columns are actually stored as TEXT so there is no benefit for doing this anyway.

Bottom line - use VARCHAR field instead of GUID field if you want comparisons to work correctly.


  • 3rd July, 2011: Version 2.5 - Initial version (open source)
  • 5th July, 2011: Fixed the Setup.nsi file to use the correct files in the Release folder
  • 6th July, 2011: Fixed problem with 64 bit systems (changed build configuration to use x86 settings)


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

GeneralMy vote of 5 Pin
Saumitra Srivastav8-Oct-12 2:57
Saumitra Srivastav8-Oct-12 2:57 
GeneralRe: My vote of 5 Pin
liron.levi8-Oct-12 4:28
professionalliron.levi8-Oct-12 4:28 
GeneralMy vote of 5 Pin
Kanasz Robert24-Sep-12 6:02
professionalKanasz Robert24-Sep-12 6:02 
QuestionGenerate SQL from diffs Pin
Mithir24-Jul-12 0:29
Mithir24-Jul-12 0:29 
AnswerRe: Generate SQL from diffs Pin
liron.levi24-Jul-12 9:37
professionalliron.levi24-Jul-12 9:37 
Questiondata of new tables are not included in the change script Pin
thaeger18-Jul-12 2:17
thaeger18-Jul-12 2:17 
AnswerRe: data of new tables are not included in the change script Pin
liron.levi18-Jul-12 5:06
professionalliron.levi18-Jul-12 5:06 
GeneralMy vote of 5 Pin
smeng21-Jun-12 23:34
smeng21-Jun-12 23:34 
Awesome stuff! Keep up the good job!
GeneralMy vote of 5 Pin
Win32nipuh23-May-12 6:38
professionalWin32nipuh23-May-12 6:38 
QuestionMy vote of 5 Pin
ipodipad2-May-12 0:00
ipodipad2-May-12 0:00 
AnswerRe: My vote of 5 Pin
liron.levi2-May-12 7:53
professionalliron.levi2-May-12 7:53 
GeneralGreat Tool Pin
deyadav18-Mar-12 13:17
deyadav18-Mar-12 13:17 
GeneralRe: Great Tool Pin
liron.levi18-Mar-12 22:47
professionalliron.levi18-Mar-12 22:47 
GeneralMy vote of 5 Pin
KevinQiang.K5-Jan-12 22:38
KevinQiang.K5-Jan-12 22:38 
Questionlarge databases miss the last entry Pin
samk6423-Dec-11 5:13
samk6423-Dec-11 5:13 
AnswerRe: large databases miss the last entry Pin
liron.levi23-Dec-11 5:40
professionalliron.levi23-Dec-11 5:40 
QuestionMy vote of 5... Pin
Jun Du24-Nov-11 4:17
Jun Du24-Nov-11 4:17 
Questionencrypted databases Pin
Savas Cilve22-Nov-11 7:02
Savas Cilve22-Nov-11 7:02 
AnswerRe: encrypted databases Pin
liron.levi22-Nov-11 7:25
professionalliron.levi22-Nov-11 7:25 
GeneralRe: encrypted databases Pin
Savas Cilve22-Nov-11 7:40
Savas Cilve22-Nov-11 7:40 
GeneralMy vote of 5 Pin
Pedro Hernández31-Aug-11 18:40
Pedro Hernández31-Aug-11 18:40 
QuestionGreat tool Pin
BenOram2-Aug-11 17:46
BenOram2-Aug-11 17:46 
GeneralMy vote of 5 Pin
svjavier21-Jul-11 23:53
svjavier21-Jul-11 23:53 
QuestionError on opening db Pin
WillemSe4-Jul-11 21:50
WillemSe4-Jul-11 21:50 
AnswerRe: Error on opening db Pin
liron.levi5-Jul-11 1:58
professionalliron.levi5-Jul-11 1:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.