Click here to Skip to main content
11,431,483 members (71,582 online)
Click here to Skip to main content
Articles » Database » Database » SQL Server » Downloads
Add your own
alternative version

SQLite Compare Utility

, 21 Feb 2015 LGPL3
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.Text;
using System.IO;
using System.Web;
using System.Net;
using System.Collections.Specialized;
using Common;

namespace SQLiteTurbo
{
    /// <summary>
    /// Submits post data to a url.
    /// </summary>
    public class PostSubmitter
    {
        /// <summary>
        /// determines what type of post to perform.
        /// </summary>
        public enum PostTypeEnum
        {
            /// <summary>
            /// Does a get against the source.
            /// </summary>
            Get,
            /// <summary>
            /// Does a post against the source.
            /// </summary>
            Post
        }

        /// <summary>
        /// Default constructor.
        /// </summary>
        public PostSubmitter()
        {
        }

        /// <summary>
        /// Constructor that accepts a url as a parameter
        /// </summary>
        /// <param name="url">The url where the post will be submitted to.</param>
        public PostSubmitter(string url)
            : this()
        {
            m_url = url;
        }

        /// <summary>
        /// Constructor allowing the setting of the url and items to post.
        /// </summary>
        /// <param name="url">the url for the post.</param>
        /// <param name="values">The values for the post.</param>
        public PostSubmitter(string url, NameValueCollection values)
            : this(url)
        {
            m_values = values;
        }

        /// <summary>
        /// Gets or sets the url to submit the post to.
        /// </summary>
        public string Url
        {
            get
            {
                return m_url;
            }
            set
            {
                m_url = value;
            }
        }
        /// <summary>
        /// Gets or sets the name value collection of items to post.
        /// </summary>
        public NameValueCollection PostItems
        {
            get
            {
                return m_values;
            }
            set
            {
                m_values = value;
            }
        }

        /// <summary>
        /// Gets or sets the type of action to perform against the url.
        /// </summary>
        public PostTypeEnum Type
        {
            get
            {
                return m_type;
            }
            set
            {
                m_type = value;
            }
        }

        /// <summary>
        /// Cancels an on-going POST operation
        /// </summary>
        public void CancelPost()
        {
            lock (this)
            {
                if (_worker != null && _worker.IsAlive)
                    _worker.Interrupt();
            } // lock
        }

        /// <summary>
        /// Posts the supplied data to specified url.
        /// </summary>
        /// <returns>a string containing the result of the post.</returns>
        public string Post()
        {
            StringBuilder parameters = new StringBuilder();
            for (int i = 0; i < m_values.Count; i++)
            {
                EncodeAndAddItem(ref parameters, m_values.GetKey(i), m_values[i]);
            }
            string result = PostData(m_url, parameters.ToString());
            return result;
        }

        /// <summary>
        /// Posts the supplied data to specified url.
        /// </summary>
        /// <param name="url">The url to post to.</param>
        /// <returns>a string containing the result of the post.</returns>
        public string Post(string url)
        {
            m_url = url;
            return this.Post();
        }

        /// <summary>
        /// Posts the supplied data to specified url.
        /// </summary>
        /// <param name="url">The url to post to.</param>
        /// <param name="values">The values to post.</param>
        /// <returns>a string containing the result of the post.</returns>
        public string Post(string url, NameValueCollection values)
        {
            m_values = values;
            return this.Post(url);
        }

        /// <summary>
        /// Posts data to a specified url. Note that this assumes that you have already url encoded the post data.
        /// </summary>
        /// <param name="postData">The data to post.</param>
        /// <param name="url">the url to post to.</param>
        /// <returns>Returns the result of the post.</returns>
        private string PostData(string url, string postData)
        {
            lock (this)
            {
                if (_busy)
                    throw new InvalidOperationException("Another PostData operation is active");
                _busy = true;
            } // lock

            string result = string.Empty;
            bool cancelled = false;
            Exception error = null;

            _worker = new Thread(new ThreadStart(delegate
            {
                try
                {
                    HttpWebRequest request = null;
                    if (m_type == PostTypeEnum.Post)
                    {
                        Uri uri = new Uri(url);
                        request = (HttpWebRequest)WebRequest.Create(uri);
                        request.Timeout = 10000;
                        request.Method = "POST";
                        request.ContentType = "application/x-www-form-urlencoded";
                        request.ContentLength = postData.Length;
                        using (Stream writeStream = request.GetRequestStream())
                        {
                            UTF8Encoding encoding = new UTF8Encoding();
                            byte[] bytes = encoding.GetBytes(postData);
                            writeStream.Write(bytes, 0, bytes.Length);
                        }
                    }
                    else
                    {
                        Uri uri = new Uri(url + "?" + postData);
                        request = (HttpWebRequest)WebRequest.Create(uri);
                        request.Method = "GET";
                    }

                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        using (Stream responseStream = response.GetResponseStream())
                        {
                            using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                            {
                                result = readStream.ReadToEnd();
                            }
                        }
                    }
                }
                catch (ThreadInterruptedException tex)
                {
                    cancelled = true;
                } // catch
                catch (Exception ex)
                {
                    error = ex;
                }
            }));

            try
            {
                _worker.IsBackground = true;
                _worker.Name = "PostData Thread";
                _worker.Start();

                // Wait for the worker thread to complete
                _worker.Join();

                if (cancelled)
                    throw new UserCancellationException();

                if (error != null)
                    throw error;
            }
            finally
            {
                lock (this)
                    _busy = false;
            } // finally

            return result;
        }

        /// <summary>
        /// Encodes an item and ads it to the string.
        /// </summary>
        /// <param name="baseRequest">The previously encoded data.</param>
        /// <param name="dataItem">The data to encode.</param>
        /// <returns>A string containing the old data and the previously encoded data.</returns>
        private void EncodeAndAddItem(ref StringBuilder baseRequest, string key, string dataItem)
        {
            if (baseRequest == null)
            {
                baseRequest = new StringBuilder();
            }
            if (baseRequest.Length != 0)
            {
                baseRequest.Append("&");
            }
            baseRequest.Append(key);
            baseRequest.Append("=");
            baseRequest.Append(System.Web.HttpUtility.UrlEncode(dataItem));
        }

        #region Private Variables
        private string m_url = string.Empty;
        private NameValueCollection m_values = new NameValueCollection();
        private PostTypeEnum m_type = PostTypeEnum.Get;
        private Thread _worker = null;
        private bool _busy = false;
        #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 | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 22 Feb 2015
Article Copyright 2011 by liron.levi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid