Click here to Skip to main content
Click here to Skip to main content

SQLite Compare Utility

, 6 Jul 2011
Rate this:
Please Sign up or sign in to vote.
Utility for comparing two SQLite database files for both structure and data
SQLite Compare Screenshot

Introduction

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!

History

  • 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)

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

About the Author

liron.levi
Software Developer Arineta Cardio Imaging
Israel Israel
My name is Liron Levi and I'm developing software for fun & profit for 15 years already. I'm now working for Arineta Cardio Imaging as a software developer (the company develops a CT machine).
 
I can be contacted directly at liron.levi@outlook.com or via linkedin at http://www.linkedin.com/pub/liron-levy/1/578/ab5

Comments and Discussions

 
QuestionGreat tool Pinmembereraneran1238-May-14 2:23 
GeneralMy vote of 5 Pinmemberferzaca7-May-14 2:47 
GeneralMy vote of 5 PinmemberMember 107209572-Apr-14 22:24 
GeneralMy vote of 5 PinmemberMember 36544646-Feb-14 3:39 
QuestionUpdates for .NET 4.5.1 ? Pinmemberkiquenet.com31-Jan-14 4:33 
GeneralMy vote of 5 PinmemberNeven Rodic2-Sep-13 3:59 
GeneralMy vote of 5 Pinmemberzerochangjj31-Jul-13 22:50 
Generalso cool PinmemberAppleDragon10-Apr-13 23:33 
Questioncollation support PinmemberPeter Gordos7-Mar-13 23:14 
AnswerRe: collation support Pinmemberliron.levi9-Mar-13 21:03 
BugDoesn't work PinmemberMember 976089814-Feb-13 10:46 
QuestionCommand line Pinmemberscarvenger_C++8-Jan-13 8:13 
AnswerRe: Command line Pinmemberliron.levi26-Jan-13 19:58 
GeneralVery neat tool... PinmemberPrakash RBB4-Dec-12 5:15 
GeneralMy vote of 5 PinmemberSaumitra Srivastav8-Oct-12 2:57 
GeneralRe: My vote of 5 Pinmemberliron.levi8-Oct-12 4:28 
GeneralMy vote of 5 PinmvpKanasz Robert24-Sep-12 6:02 
QuestionGenerate SQL from diffs PinmemberMember 765453424-Jul-12 0:29 
AnswerRe: Generate SQL from diffs Pinmemberliron.levi24-Jul-12 9:37 
Questiondata of new tables are not included in the change script Pinmemberthaeger18-Jul-12 2:17 
AnswerRe: data of new tables are not included in the change script Pinmemberliron.levi18-Jul-12 5:06 
Please make sure to select the "Compare Data" radio button in the comparison dialog. It should be able to copy the relevant data.
 
Thanks
Liron
GeneralMy vote of 5 Pinmembersmeng21-Jun-12 23:34 
GeneralMy vote of 5 PinmemberWin32nipuh23-May-12 6:38 
QuestionMy vote of 5 Pinmemberminkyupark2-May-12 0:00 
AnswerRe: My vote of 5 Pinmemberliron.levi2-May-12 7:53 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 6 Jul 2011
Article Copyright 2011 by liron.levi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid