Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » SQL Server » Downloads
 

SQLite Compare Utility

By , 6 Jul 2011
 
SQLiteCompare.zip
SQLiteCompare
AutomaticUpdates
Properties
Be.Windows.Forms.HexBox
Design
HexBox.bmp
HexBox.snk
Thumbs.db
Common
Properties
CreateTestDatabases
Properties
TestSchemaFiles
DiffControl
Properties
FastGrid
Properties
Settings.settings
gplex.exe
gplexx.frame
gppg.exe
license.lic
Liron.Windows.Forms
Design
multipanel.ico
Properties
Thumbs.db
log4net.dll
Puzzle.SyntaxBox.NET3.5.dll
Setup
appicon.ico
finish_banner.bmp
installer_banner.bmp
setup.nsi
Thumbs.db
uninstallicon.ico
ShiftReduceParser.dll
SQLiteParser
Properties
sqlite.lex
sqlite.y
SQLiteTurbo
Properties
Settings.settings
Resources
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
feedback2.png
normal_feedback_button.png
pressed_feedback_button.png
sqlite.syn
SQLiteTurbo.csproj.user
SQLiteTurboDiff.suo
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
System.Data.SQLite.dll
UndoRedo
Properties
SQLiteCompareSetup.zip
SQLiteCompareSetup.exe
SQLiteCompare_src.zip
HexBox.bmp
HexBox.snk
Thumbs.db
Settings.settings
gplex.exe
gplexx.frame
gppg.exe
license.lic
multipanel.ico
Thumbs.db
log4net.dll
Puzzle.SyntaxBox.NET3.5.dll
appicon.ico
finish_banner.bmp
installer_banner.bmp
setup.nsi
Thumbs.db
uninstallicon.ico
ShiftReduceParser.dll
sqlite.lex
sqlite.y
Settings.settings
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
feedback2.png
normal_feedback_button.png
pressed_feedback_button.png
sqlite.syn
SQLiteTurbo.csproj.user
SQLiteTurboDiff.suo
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
System.Data.SQLite.dll
using System;
using System.Collections.Generic;
using System.Text;

namespace SQLiteTurbo
{
    /// <summary>
    /// This class provides an implementation for saving BLOB fields from a file to the 
    /// BLOB field that is specified in the constructor
    /// </summary>
    public class BlobSaver : AbstractWorker, IDisposable
    {
        #region Constructors & Destructors
        public BlobSaver(string dbpath, string tableName, string columnName, long rowId, string blobFile)
            : base("BlobSaver")
        {
            _blobWriter = new BlobReaderWriter(dbpath, false);
            _tableName = tableName;
            _columnName = columnName;
            _rowId = rowId;
            _blobFile = blobFile;
        }

        public BlobSaver(string dbpath, string tableName, string columnName, long rowId, byte[] buffer)
            : base("BlobSaver")
        {
            _blobWriter = new BlobReaderWriter(dbpath, false);
            _tableName = tableName;
            _columnName = columnName;
            _rowId = rowId;
            _buffer = buffer;
        }

        ~BlobSaver()
        {
            Dispose(false);
        }
        #endregion

        #region Protected Overrided Methods
        protected override void DoWork()
        {
            if (_blobFile != null)
            {
                _blobWriter.WriteBlobFromFile(_tableName, _columnName, _rowId, _blobFile, ProgressHandler);
            }
            else
            {
                _blobWriter.WriteBlob(_tableName, _columnName, _rowId, _buffer.Length, MemoryWriter);
            } // else
        }

        protected override bool IsDualProgress
        {
            get
            {
                return false;
            }
        }
        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);     
        }

        #endregion

        #region Protected Virtual Methods
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Release managed resources
                    _blobWriter.Dispose();
                }

                // Mark that the object was disposed
                _disposed = true;
            }
        }
        #endregion

        #region Private Methods
        private int MemoryWriter(byte[] buffer, int max, int written, int total, ref bool cancel)
        {
            ProgressHandler(buffer, max, written, total, ref cancel);

            int nbytes = _buffer.Length;
            if (nbytes > max)
                nbytes = max;
            Buffer.BlockCopy(_buffer, written, buffer, 0, nbytes);
            return nbytes;
        }

        private int ProgressHandler(byte[] buffer, int max, int written, int total, ref bool cancel)
        {
            cancel = this.WasCancelled;

            int progress = (int)(100.0 * written / total);
            if (progress > _progress)
            {
                NotifyPrimaryProgress(false, progress, 
                    Utils.FormatMemSize(written, MemFormat.KB) + "/" + 
                    Utils.FormatMemSize(total, MemFormat.KB) + " written so far", null);
                _progress = progress;
            }

            // Insignificant since the blob file writer ignores my return codes.
            return max;
        }
        #endregion

        #region Private Variables
        private long _rowId;
        private string _blobFile;
        private byte[] _buffer;
        private string _tableName;
        private string _columnName;
        private int _progress = 0;
        private bool _disposed;
        private BlobReaderWriter _blobWriter = null;
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of use 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)

About the Author

liron.levi
Software Developer Arineta Cardio Imaging
Israel Israel
Member
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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 6 Jul 2011
Article Copyright 2011 by liron.levi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid