Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » SQL Server » Downloads
 
Add your own
alternative version
Go to top

SQLite Compare Utility

, 6 Jul 2011
Utility for comparing two SQLite database files for both structure and data
SQLiteCompare.zip
SQLiteCompare
gplex.exe
gplexx.frame
gppg.exe
license.lic
log4net.dll
Puzzle.SyntaxBox.NET3.5.dll
ShiftReduceParser.dll
SQLiteTurboDiff.suo
System.Data.SQLite.dll
AutomaticUpdates
Properties
Be.Windows.Forms.HexBox
HexBox.bmp
HexBox.snk
Thumbs.db
Design
Common
Properties
CreateTestDatabases
Properties
TestSchemaFiles
DiffControl
Properties
FastGrid
Properties
Settings.settings
Liron.Windows.Forms
multipanel.ico
Thumbs.db
Design
Properties
Setup
appicon.ico
finish_banner.bmp
installer_banner.bmp
setup.nsi
Thumbs.db
uninstallicon.ico
SQLiteParser
sqlite.lex
sqlite.y
Properties
SQLiteTurbo
sqlite.syn
SQLiteTurbo.csproj.user
Properties
Settings.settings
Resources
feedback2.png
feedback_non_selected_idea.png
feedback_non_selected_question.png
feedback_pressed.png
feedback_problem_non_selected.png
feedback_problem_selected.png
feedback_selected_idea.png
feedback_selected_question.png
normal_feedback_button.png
pressed_feedback_button.png
SVG
about.svg
accept.svg
app.svg
appicon.svg
bug.svg
check_updates.svg
close_comparison.svg
company_tagline.svg
compare.svg
copy_from_left_db.svg
copy_from_right_db.svg
edit_selected_difference.svg
feather.svg
feedback.svg
feedback_frame.svg
feedback_non_selected_idea.svg
feedback_non_selected_problem.svg
feedback_question.svg
feedback_selected_problem.svg
feedback_selected_question.svg
finish_page_banner.svg
free.svg
generate_script_left_to_right.svg
generate_script_right_to_left.svg
greenpinesoftware_logo.svg
home_screenshot.svg
installer_banner.svg
key.svg
lamp.svg
lamp_non_selected.svg
lamp_selected.svg
lock.svg
main_screen.svg
next_diff.svg
prev_diff.svg
question.svg
recycle_bin.svg
redo.svg
reject.svg
reorder_columns.svg
save_schema.svg
search.svg
smallbug.svg
sqlite_compare_logo.svg
sqlite_feather.svg
text2451.png
undo.svg
uninstall.svg
v_bullet.svg
UndoRedo
Properties
SQLiteCompareSetup.zip
SQLiteCompareSetup.exe
SQLiteCompare_src.zip
gplex.exe
gplexx.frame
gppg.exe
license.lic
log4net.dll
Puzzle.SyntaxBox.NET3.5.dll
ShiftReduceParser.dll
SQLiteTurboDiff.suo
System.Data.SQLite.dll
HexBox.bmp
HexBox.snk
Thumbs.db
Settings.settings
multipanel.ico
Thumbs.db
appicon.ico
finish_banner.bmp
installer_banner.bmp
setup.nsi
Thumbs.db
uninstallicon.ico
sqlite.lex
sqlite.y
sqlite.syn
SQLiteTurbo.csproj.user
Settings.settings
feedback2.png
feedback_non_selected_idea.png
feedback_non_selected_question.png
feedback_pressed.png
feedback_problem_non_selected.png
feedback_problem_selected.png
feedback_selected_idea.png
feedback_selected_question.png
normal_feedback_button.png
pressed_feedback_button.png
about.svg
accept.svg
app.svg
appicon.svg
bug.svg
check_updates.svg
close_comparison.svg
company_tagline.svg
compare.svg
copy_from_left_db.svg
copy_from_right_db.svg
edit_selected_difference.svg
feather.svg
feedback.svg
feedback_frame.svg
feedback_non_selected_idea.svg
feedback_non_selected_problem.svg
feedback_question.svg
feedback_selected_problem.svg
feedback_selected_question.svg
finish_page_banner.svg
free.svg
generate_script_left_to_right.svg
generate_script_right_to_left.svg
greenpinesoftware_logo.svg
home_screenshot.svg
installer_banner.svg
key.svg
lamp.svg
lamp_non_selected.svg
lamp_selected.svg
lock.svg
main_screen.svg
next_diff.svg
prev_diff.svg
question.svg
recycle_bin.svg
redo.svg
reject.svg
reorder_columns.svg
save_schema.svg
search.svg
smallbug.svg
sqlite_compare_logo.svg
sqlite_feather.svg
text2451.png
undo.svg
uninstall.svg
v_bullet.svg
using System;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SQLiteParser;
using Common;
using AutomaticUpdates;
using log4net;

namespace SQLiteTurbo
{
    /// <summary>
    /// This class is the main form of the application.
    /// </summary>
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        #region Event Handlers

        private void MainForm_Load(object sender, EventArgs e)
        {
            UpdateState();
        }

        private void btnCompare_Click(object sender, EventArgs e)
        {
            HandleCompareDialog();
        }

        private void mniCompare_Click(object sender, EventArgs e)
        {
            HandleCompareDialog();
        }

        private void mniCloseComparison_Click(object sender, EventArgs e)
        {
            CleanupSchemaView();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            CleanupSchemaView();
        }

        private void btnNextDiff_Click(object sender, EventArgs e)
        {
            _schemaView.MoveToNextDiff();
        }

        private void btnPreviousDiff_Click(object sender, EventArgs e)
        {
            _schemaView.MoveToPreviousDiff();
        }

        private void _schemaView_SelectionChanged(object sender, EventArgs e)
        {
            UpdateState();
        }

        private void mniCopyFromLeftDB_Click(object sender, EventArgs e)
        {
            _schemaView.CopyFromLeftDB();
        }

        private void mniCopyFromRightDB_Click(object sender, EventArgs e)
        {
            _schemaView.CopyFromRightDB();
        }

        private void btnEditSelectedDifference_Click(object sender, EventArgs e)
        {
            _schemaView.OpenCompareDialog();
        }

        private void mniEditSelection_Click(object sender, EventArgs e)
        {
            _schemaView.OpenCompareDialog();
        }

        private void mniGotoNextDifference_Click(object sender, EventArgs e)
        {
            _schemaView.MoveToNextDiff();
        }

        private void mniGotoPreviousDifference_Click(object sender, EventArgs e)
        {
            _schemaView.MoveToPreviousDiff();
        }

        private void btnCopyFromLeftDB_Click(object sender, EventArgs e)
        {
            _schemaView.CopyFromLeftDB();
        }

        private void btnCopyFromRightDB_Click(object sender, EventArgs e)
        {
            _schemaView.CopyFromRightDB();
        }

        private void mniAbout_Click(object sender, EventArgs e)
        {
            AboutDialog dlg = new AboutDialog();
            dlg.ShowDialog(this);
        }

        private void mniExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void mniReport_Click(object sender, EventArgs e)
        {
            WebSiteUtils.OpenBugFeaturePage();
        }

        private void mniGenerateChangeScriptLeftToRight_Click(object sender, EventArgs e)
        {
            string sql = ChangeScriptBuilder.Generate(_leftdb, _rightdb, _leftSchema, _rightSchema, _results, ChangeDirection.LeftToRight);

            ChangeScriptDialog dlg = new ChangeScriptDialog();
            dlg.Prepare(sql);
            dlg.ShowDialog(this);
        }

        private void mniGenerateChangeScriptRightToLeft_Click(object sender, EventArgs e)
        {
            string sql = ChangeScriptBuilder.Generate(_leftdb, _rightdb, _leftSchema, _rightSchema, _results, ChangeDirection.RightToLeft);

            ChangeScriptDialog dlg = new ChangeScriptDialog();
            dlg.Prepare(sql);
            dlg.ShowDialog(this);
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            UpdateTitle();

            // The first time the software is ran - it should prompt the user if he wants to enable
            // checking for software updates upon system startup
            if (Configuration.FirstTime)
            {
                Configuration.FirstTime = false;

                FirstTimeDialog fdlg = new FirstTimeDialog();
                DialogResult res = fdlg.ShowDialog(this);
                Configuration.CheckUpdatesOnStartup = fdlg.IsAutomaticUpdates;
                if (res == DialogResult.OK)
                {
                    CheckUpdatesDialog cdlg = new CheckUpdatesDialog();
                    cdlg.ShowDialog(this);
                } // else
            }
            else
            {
                // Check for software updates if necessary
                CheckSoftwareUpdates();
            }
        }

        private void mniProductWebsite_Click(object sender, EventArgs e)
        {
            WebSiteUtils.OpenProductPage();
        }

        private void mniUserGuide_Click(object sender, EventArgs e)
        {
            WebSiteUtils.OpenUserGuidePage();
        }

        private void mniCheckForUpdates_Click(object sender, EventArgs e)
        {
            CheckUpdatesDialog dlg = new CheckUpdatesDialog();
            dlg.ShowDialog(this);
        }

        private void pbxFeedback_MouseDown(object sender, MouseEventArgs e)
        {
            pbxFeedback.Image = Properties.Resources.pressed_feedback_button;
        }

        private void pbxFeedback_MouseUp(object sender, MouseEventArgs e)
        {
            pbxFeedback.Image = Properties.Resources.normal_feedback_button;
            if (pbxFeedback.ClientRectangle.Contains(e.Location))
            {
                pbxFeedback.Visible = false;
                FeedbackDialog dlg = new FeedbackDialog();
                dlg.ShowDialog(this);
                pbxFeedback.Visible = true;
            }
        }

        private void btnExportDataDifferences_Click(object sender, EventArgs e)
        {
            _schemaView.ExportDataDifferences();
        }

        #endregion

        #region Private Methods

        private void UpdateTitle()
        {
            this.Text = "SQLite Compare";
        }

        /// <summary>
        /// Allows to refresh the comparison results
        /// </summary>
        /// <param name="cancellable">TRUE means that the user will be allowed to cancel
        /// the comparison process. FALSE prevents this from happening (by making the CANCEL
        /// button disabled).</param>
        private void RefreshComparison(bool cancellable)
        {
            CompareWorker worker = new CompareWorker(_compareParams);
            ProgressDialog pdlg = new ProgressDialog();
            if (cancellable)
                pdlg.Start(this, worker);
            else
                pdlg.StartNonCancellable(this, worker);

            Dictionary<SchemaObject, List<SchemaComparisonItem>> results =
                (Dictionary<SchemaObject, List<SchemaComparisonItem>>)pdlg.Result;
            if (results != null)
            {
                // Create the schema comparison view and populate it with the results
                if (_schemaView == null)
                {
                    _schemaView = new SchemaComparisonView();
                    _schemaView.BackColor = SystemColors.Control;
                    pnlContents.Controls.Add(_schemaView);
                    _schemaView.Dock = DockStyle.Fill;
                    _schemaView.SelectionChanged += new EventHandler(_schemaView_SelectionChanged);
                }

                _leftSchema = worker.LeftSchema;
                _rightSchema = worker.RightSchema;
                _results = results;
                _leftdb = _compareParams.LeftDbPath;
                _rightdb = _compareParams.RightDbPath;

                _schemaView.ShowComparisonResults(results, _compareParams.LeftDbPath, _compareParams.RightDbPath,
                    worker.LeftSchema, worker.RightSchema, _compareParams.ComparisonType == ComparisonType.CompareSchemaAndData);
            }

            UpdateState();
        }

        private void CleanupSchemaView()
        {
            if (_schemaView == null)
                return;

            // Delete all temporary comparison files.
            foreach (SchemaComparisonItem item in _schemaView.Results[SchemaObject.Table])
            {
                if (item.TableChanges != null)
                    item.TableChanges.Dispose();
            } // foreach

            // Hide the schema view control
            pnlContents.Controls.Remove(_schemaView);
            _schemaView.SelectionChanged -= new EventHandler(_schemaView_SelectionChanged);
            _schemaView.Dispose();
            _schemaView = null;            

            _leftSchema = _rightSchema = null;
            _results = null;

            UpdateState();
        }

        private void UpdateState()
        {
            btnNextDiff.Enabled = _schemaView != null && _schemaView.HasNextDiff();
            btnPreviousDiff.Enabled = _schemaView != null && _schemaView.HasPreviousDiff();
            btnCopyFromLeftDB.Enabled = _schemaView != null && _schemaView.CanCopyFromLeftDB();
            btnCopyFromRightDB.Enabled = _schemaView != null && _schemaView.CanCopyFromRightDB();
            btnEditSelectedDifference.Enabled = _schemaView != null && _schemaView.CanEditSelectedDifference();
            mniCopyFromLeftDB.Enabled = _schemaView != null && _schemaView.CanCopyFromLeftDB();
            mniCopyFromRightDB.Enabled = _schemaView != null && _schemaView.CanCopyFromRightDB();
            mniEditSelection.Enabled = _schemaView != null && _schemaView.CanEditSelectedDifference();
            mniGotoNextDifference.Enabled = _schemaView != null && _schemaView.HasNextDiff();
            mniGotoPreviousDifference.Enabled = _schemaView != null && _schemaView.HasPreviousDiff();
            pbxFeedback.Visible = _schemaView == null;            

            #region Allow change script generation only to commercial/evaluation users

            bool allowedGenerateScripts = false;
            allowedGenerateScripts = true;

            mniGenerateChangeScriptLeftToRight.Enabled = _schemaView != null && allowedGenerateScripts;
            mniGenerateChangeScriptRightToLeft.Enabled = _schemaView != null && allowedGenerateScripts;
            mniCloseComparison.Enabled = _schemaView != null;
            btnExportDataDifferences.Enabled = _schemaView != null && _schemaView.HasDataDiffs() && allowedGenerateScripts;

            #endregion
        }

        private void HandleCompareDialog()
        {
            CompareDialog dlg = new CompareDialog();
            dlg.CompareParams = _compareParams;
            DialogResult res = dlg.ShowDialog(this);
            if (res == DialogResult.Cancel)
                return;

            // Collect the comparison parameters from the user and do the comparison.
            _compareParams = dlg.CompareParams;
            RefreshComparison(true);
        }

        /// <summary>
        /// Check if there are software updates and show the updates dialog if necessary
        /// </summary>
        private void CheckSoftwareUpdates()
        {
            // Check for software updates if necessary
            if (Configuration.CheckUpdatesOnStartup)
            {
                mniCheckForUpdates.Enabled = false;
                WaitCallback wc = delegate
                {
                    try
                    {
                        //List<VersionUpdateInfo> vlist = UpdateEngine.CheckForUpdates();
                        List<VersionUpdateInfo> vlist = null;
                        if (vlist != null)
                        {
                            // There are updates waiting
                            Invoke(new MethodInvoker(delegate
                            {
                                CheckUpdatesDialog cdlg = new CheckUpdatesDialog();
                                cdlg.ShowDownloadPage(this, vlist);
                            }));
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Warn("failed to check for software updates", ex);
                    } // catch
                    finally
                    {
                        // The window may have been disposed as a result of shutting down the application.
                        if (!UpdateEngine.IsReInstalling)
                        {
                            try
                            {
                                Invoke(new MethodInvoker(delegate
                                {
                                    mniCheckForUpdates.Enabled = true;
                                }));
                            }
                            catch (ObjectDisposedException ode)
                            {
                                // Ignore
                            }
                        } // if
                    } // finally
                };
                ThreadPool.QueueUserWorkItem(wc);
            }
        }
        #endregion

        #region Private Variables       
        private SchemaComparisonView _schemaView = null;
        private CompareParams _compareParams = null;
        private string _leftdb;
        private string _rightdb;
        private ILog _log = LogManager.GetLogger(typeof(MainForm));
        private Dictionary<SchemaObject, List<SchemaComparisonItem>> _results;
        private Dictionary<SchemaObject, Dictionary<string, SQLiteDdlStatement>> _leftSchema;
        private Dictionary<SchemaObject, Dictionary<string, SQLiteDdlStatement>> _rightSchema;
        #endregion
    }
}

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)

Share

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

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