/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Joe Mistachkin (joe@mistachkin.com)
*
* Released to the public domain, use at your own risk!
********************************************************/
using System.Collections.Generic;
namespace System.Data.SQLite
{
///
/// This class implements a virtual table module that does nothing by
/// providing "empty" implementations for all of the
/// interface methods. The result
/// codes returned by these "empty" method implementations may be
/// controlled on a per-method basis by using and/or overriding the
/// ,
/// ,
/// ,
/// , and
/// methods from within derived classes.
///
public class SQLiteModuleNoop : SQLiteModule /* NOT SEALED */
{
#region Private Data
///
/// This field is used to store the
/// values to return, on a per-method basis, for all methods that are
/// part of the interface.
///
private Dictionary resultCodes;
#endregion
///////////////////////////////////////////////////////////////////////
#region Public Constructors
///
/// Constructs an instance of this class.
///
///
/// The name of the module. This parameter cannot be null.
///
public SQLiteModuleNoop(
string name
)
: base(name)
{
resultCodes = new Dictionary();
}
#endregion
///////////////////////////////////////////////////////////////////////
#region Protected Methods
///
/// Determines the default value to be
/// returned by methods of the
/// interface that lack an overridden implementation in all classes
/// derived from the class.
///
///
/// The value that should be returned
/// by all interface methods unless
/// a more specific result code has been set for that interface method.
///
protected virtual SQLiteErrorCode GetDefaultResultCode()
{
return SQLiteErrorCode.Ok;
}
///////////////////////////////////////////////////////////////////////
///
/// Converts a value into a boolean
/// return value for use with the
/// method.
///
///
/// The value to convert.
///
///
/// The value.
///
protected virtual bool ResultCodeToEofResult(
SQLiteErrorCode resultCode
)
{
return (resultCode == SQLiteErrorCode.Ok) ? false : true;
}
///////////////////////////////////////////////////////////////////////
///
/// Converts a value into a boolean
/// return value for use with the
/// method.
///
///
/// The value to convert.
///
///
/// The value.
///
protected virtual bool ResultCodeToFindFunctionResult(
SQLiteErrorCode resultCode
)
{
return (resultCode == SQLiteErrorCode.Ok) ? true : false;
}
///////////////////////////////////////////////////////////////////////
///
/// Determines the value that should be
/// returned by the specified
/// interface method if it lack an overridden implementation. If no
/// specific value is available (or set)
/// for the specified method, the value
/// returned by the method will be
/// returned instead.
///
///
/// The name of the method. Currently, this method must be part of
/// the interface.
///
///
/// The value that should be returned
/// by the interface method.
///
protected virtual SQLiteErrorCode GetMethodResultCode(
string methodName
)
{
if ((methodName == null) || (resultCodes == null))
return GetDefaultResultCode();
SQLiteErrorCode resultCode;
if ((resultCodes != null) &&
resultCodes.TryGetValue(methodName, out resultCode))
{
return resultCode;
}
return GetDefaultResultCode();
}
///////////////////////////////////////////////////////////////////////
///
/// Sets the value that should be
/// returned by the specified
/// interface method if it lack an overridden implementation.
///
///
/// The name of the method. Currently, this method must be part of
/// the interface.
///
///
/// The value that should be returned
/// by the interface method.
///
///
/// Non-zero upon success.
///
protected virtual bool SetMethodResultCode(
string methodName,
SQLiteErrorCode resultCode
)
{
if ((methodName == null) || (resultCodes == null))
return false;
resultCodes[methodName] = resultCode;
return true;
}
#endregion
///////////////////////////////////////////////////////////////////////
#region ISQLiteManagedModule Members
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Create(
SQLiteConnection connection,
IntPtr pClientData,
string[] arguments,
ref SQLiteVirtualTable table,
ref string error
)
{
CheckDisposed();
return GetMethodResultCode("Create");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Connect(
SQLiteConnection connection,
IntPtr pClientData,
string[] arguments,
ref SQLiteVirtualTable table,
ref string error
)
{
CheckDisposed();
return GetMethodResultCode("Connect");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode BestIndex(
SQLiteVirtualTable table,
SQLiteIndex index
)
{
CheckDisposed();
return GetMethodResultCode("BestIndex");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Disconnect(
SQLiteVirtualTable table
)
{
CheckDisposed();
return GetMethodResultCode("Disconnect");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Destroy(
SQLiteVirtualTable table
)
{
CheckDisposed();
return GetMethodResultCode("Destroy");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Open(
SQLiteVirtualTable table,
ref SQLiteVirtualTableCursor cursor
)
{
CheckDisposed();
return GetMethodResultCode("Open");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Close(
SQLiteVirtualTableCursor cursor
)
{
CheckDisposed();
return GetMethodResultCode("Close");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Filter(
SQLiteVirtualTableCursor cursor,
int indexNumber,
string indexString,
SQLiteValue[] values
)
{
CheckDisposed();
return GetMethodResultCode("Filter");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Next(
SQLiteVirtualTableCursor cursor
)
{
CheckDisposed();
return GetMethodResultCode("Next");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override bool Eof(
SQLiteVirtualTableCursor cursor
)
{
CheckDisposed();
return ResultCodeToEofResult(GetMethodResultCode("Eof"));
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Column(
SQLiteVirtualTableCursor cursor,
SQLiteContext context,
int index
)
{
CheckDisposed();
return GetMethodResultCode("Column");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode RowId(
SQLiteVirtualTableCursor cursor,
ref long rowId
)
{
CheckDisposed();
return GetMethodResultCode("RowId");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Update(
SQLiteVirtualTable table,
SQLiteValue[] values,
ref long rowId
)
{
CheckDisposed();
return GetMethodResultCode("Update");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Begin(
SQLiteVirtualTable table
)
{
CheckDisposed();
return GetMethodResultCode("Begin");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Sync(
SQLiteVirtualTable table
)
{
CheckDisposed();
return GetMethodResultCode("Sync");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Commit(
SQLiteVirtualTable table
)
{
CheckDisposed();
return GetMethodResultCode("Commit");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Rollback(
SQLiteVirtualTable table
)
{
CheckDisposed();
return GetMethodResultCode("Rollback");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override bool FindFunction(
SQLiteVirtualTable table,
int argumentCount,
string name,
ref SQLiteFunction function,
ref IntPtr pClientData
)
{
CheckDisposed();
return ResultCodeToFindFunctionResult(GetMethodResultCode(
"FindFunction"));
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Rename(
SQLiteVirtualTable table,
string newName
)
{
CheckDisposed();
return GetMethodResultCode("Rename");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Savepoint(
SQLiteVirtualTable table,
int savepoint
)
{
CheckDisposed();
return GetMethodResultCode("Savepoint");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode Release(
SQLiteVirtualTable table,
int savepoint
)
{
CheckDisposed();
return GetMethodResultCode("Release");
}
///////////////////////////////////////////////////////////////////////
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
///
/// See the method.
///
public override SQLiteErrorCode RollbackTo(
SQLiteVirtualTable table,
int savepoint
)
{
CheckDisposed();
return GetMethodResultCode("RollbackTo");
}
#endregion
///////////////////////////////////////////////////////////////////////
#region IDisposable "Pattern" Members
private bool disposed;
///
/// Throws an if this object
/// instance has been disposed.
///
private void CheckDisposed() /* throw */
{
#if THROW_ON_DISPOSED
if (disposed)
{
throw new ObjectDisposedException(
typeof(SQLiteModuleNoop).Name);
}
#endif
}
///////////////////////////////////////////////////////////////////////
///
/// Disposes of this object instance.
///
///
/// Non-zero if this method is being called from the
/// method. Zero if this method is
/// being called from the finalizer.
///
protected override void Dispose(bool disposing)
{
try
{
if (!disposed)
{
//if (disposing)
//{
// ////////////////////////////////////
// // dispose managed resources here...
// ////////////////////////////////////
//}
//////////////////////////////////////
// release unmanaged resources here...
//////////////////////////////////////
}
}
finally
{
base.Dispose(disposing);
//
// NOTE: Everything should be fully disposed at this point.
//
disposed = true;
}
}
#endregion
}
}