/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Robert Simpson (robert@blackcastlesoft.com)
*
* Released to the public domain, use at your own risk!
********************************************************/
namespace System.Data.SQLite
{
using System;
///
/// Represents a single SQL backup in SQLite.
///
internal sealed class SQLiteBackup : IDisposable
{
///
/// The underlying SQLite object this backup is bound to.
///
internal SQLiteBase _sql;
///
/// The actual backup handle.
///
internal SQLiteBackupHandle _sqlite_backup;
///
/// The destination database for the backup.
///
internal IntPtr _destDb;
///
/// The destination database name for the backup.
///
internal byte[] _zDestName;
///
/// The source database for the backup.
///
internal IntPtr _sourceDb;
///
/// The source database name for the backup.
///
internal byte[] _zSourceName;
///
/// The last result from the StepBackup method of the SQLite3 class.
/// This is used to determine if the call to the FinishBackup method of
/// the SQLite3 class should throw an exception when it receives a non-Ok
/// return code from the core SQLite library.
///
internal SQLiteErrorCode _stepResult;
///
/// Initializes the backup.
///
/// The base SQLite object.
/// The backup handle.
/// The destination database for the backup.
/// The destination database name for the backup.
/// The source database for the backup.
/// The source database name for the backup.
internal SQLiteBackup(
SQLiteBase sqlbase,
SQLiteBackupHandle backup,
IntPtr destDb,
byte[] zDestName,
IntPtr sourceDb,
byte[] zSourceName
)
{
_sql = sqlbase;
_sqlite_backup = backup;
_destDb = destDb;
_zDestName = zDestName;
_sourceDb = sourceDb;
_zSourceName = zSourceName;
}
///////////////////////////////////////////////////////////////////////////////////////////////
#region IDisposable Members
///
/// Disposes and finalizes the backup.
///
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////
#region IDisposable "Pattern" Members
private bool disposed;
private void CheckDisposed() /* throw */
{
#if THROW_ON_DISPOSED
if (disposed)
throw new ObjectDisposedException(typeof(SQLiteBackup).Name);
#endif
}
///////////////////////////////////////////////////////////////////////////////////////////////
private void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
////////////////////////////////////
// dispose managed resources here...
////////////////////////////////////
if (_sqlite_backup != null)
{
_sqlite_backup.Dispose();
_sqlite_backup = null;
}
_zSourceName = null;
_sourceDb = IntPtr.Zero;
_zDestName = null;
_destDb = IntPtr.Zero;
_sql = null;
}
//////////////////////////////////////
// release unmanaged resources here...
//////////////////////////////////////
disposed = true;
}
}
#endregion
///////////////////////////////////////////////////////////////////////////////////////////////
#region Destructor
~SQLiteBackup()
{
Dispose(false);
}
#endregion
}
}