/******************************************************** * 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; using System.Collections.Generic; using System.Text; using System.Data.Common; #if !PLATFORM_COMPACTFRAMEWORK using System.Runtime.Serialization; #endif /// /// SQLite exception class. /// #if !PLATFORM_COMPACTFRAMEWORK [Serializable] public sealed class SQLiteException : DbException #else public sealed class SQLiteException : Exception #endif { private SQLiteErrorCode _errorCode; #if !PLATFORM_COMPACTFRAMEWORK private SQLiteException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif /// /// Public constructor for generating a SQLite error given the base error code /// /// The SQLite error code to report /// Extra text to go along with the error message text public SQLiteException(int errorCode, string extendedInformation) : base(GetStockErrorMessage(errorCode, extendedInformation)) { _errorCode = (SQLiteErrorCode)errorCode; } /// /// Various public constructors that just pass along to the base Exception /// /// Passed verbatim to Exception public SQLiteException(string message) : base(message) { } /// /// Various public constructors that just pass along to the base Exception /// public SQLiteException() { } /// /// Various public constructors that just pass along to the base Exception /// Passed to Exception /// Passed to Exception /// public SQLiteException(string message, Exception innerException) : base(message, innerException) { } /// /// Retrieves the underlying SQLite error code for this exception /// #if !PLATFORM_COMPACTFRAMEWORK public new SQLiteErrorCode ErrorCode #else public SQLiteErrorCode ErrorCode #endif { get { return _errorCode; } } /// /// Initializes the exception class with the SQLite error code. /// /// The SQLite error code /// A detailed error message /// An error message string private static string GetStockErrorMessage(int errorCode, string errorMessage) { if (errorMessage == null) errorMessage = ""; if (errorMessage.Length > 0) errorMessage = "\r\n" + errorMessage; if (errorCode < 0 || errorCode >= _errorMessages.Length) errorCode = 1; return _errorMessages[errorCode] + errorMessage; } private static string[] _errorMessages = { "SQLite OK", "SQLite error", "An internal logic error in SQLite", "Access permission denied", "Callback routine requested an abort", "The database file is locked", "A table in the database is locked", "malloc() failed", "Attempt to write a read-only database", "Operation terminated by sqlite3_interrupt()", "Some kind of disk I/O error occurred", "The database disk image is malformed", "Table or record not found", "Insertion failed because the database is full", "Unable to open the database file", "Database lock protocol error", "Database is empty", "The database schema changed", "Too much data for one row of a table", "Abort due to constraint violation", "Data type mismatch", "Library used incorrectly", "Uses OS features not supported on host", "Authorization denied", "Auxiliary database format error", "2nd parameter to sqlite3_bind() out of range", "File opened that is not a database file", }; } /// /// SQLite error codes /// public enum SQLiteErrorCode { /// /// Success /// Ok = 0, /// /// SQL error or missing database /// Error, /// /// Internal logic error in SQLite /// Internal, /// /// Access permission denied /// Perm, /// /// Callback routine requested an abort /// Abort, /// /// The database file is locked /// Busy, /// /// A table in the database is locked /// Locked, /// /// malloc() failed /// NoMem, /// /// Attempt to write a read-only database /// ReadOnly, /// /// Operation terminated by sqlite3_interrupt() /// Interrupt, /// /// Some kind of disk I/O error occurred /// IOErr, /// /// The database disk image is malformed /// Corrupt, /// /// Table or record not found /// NotFound, /// /// Insertion failed because database is full /// Full, /// /// Unable to open the database file /// CantOpen, /// /// Database lock protocol error /// Protocol, /// /// Database is empty /// Empty, /// /// The database schema changed /// Schema, /// /// Too much data for one row of a table /// TooBig, /// /// Abort due to constraint violation /// Constraint, /// /// Data type mismatch /// Mismatch, /// /// Library used incorrectly /// Misuse, /// /// Uses OS features not supported on host /// NOLFS, /// /// Authorization denied /// Auth, /// /// Auxiliary database format error /// Format, /// /// 2nd parameter to sqlite3_bind out of range /// Range, /// /// File opened that is not a database file /// NotADatabase, /// /// sqlite3_step() has another row ready /// Row = 100, /// /// sqlite3_step() has finished executing /// Done = 101, } }