1 /********************************************************
\r
2 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
\r
3 * Written by Robert Simpson (robert@blackcastlesoft.com)
\r
5 * Released to the public domain, use at your own risk!
\r
6 ********************************************************/
\r
8 namespace Mono.Data.Sqlite
\r
11 using System.Collections.Generic;
\r
13 using System.Data.Common;
\r
15 #if !PLATFORM_COMPACTFRAMEWORK
\r
16 using System.Runtime.Serialization;
\r
20 /// SQLite exception class.
\r
22 #if !PLATFORM_COMPACTFRAMEWORK
\r
24 public sealed class SqliteException : DbException
\r
26 public sealed class SqliteException : Exception
\r
29 private SQLiteErrorCode _errorCode;
\r
31 #if !PLATFORM_COMPACTFRAMEWORK
\r
32 private SqliteException(SerializationInfo info, StreamingContext context)
\r
33 : base(info, context)
\r
39 /// Public constructor for generating a SQLite error given the base error code
\r
41 /// <param name="errorCode">The SQLite error code to report</param>
\r
42 /// <param name="extendedInformation">Extra text to go along with the error message text</param>
\r
43 public SqliteException(int errorCode, string extendedInformation)
\r
44 : base(GetStockErrorMessage(errorCode, extendedInformation))
\r
46 _errorCode = (SQLiteErrorCode)errorCode;
\r
50 /// Various public constructors that just pass along to the base Exception
\r
52 /// <param name="message">Passed verbatim to Exception</param>
\r
53 public SqliteException(string message)
\r
59 /// Various public constructors that just pass along to the base Exception
\r
61 public SqliteException()
\r
66 /// Various public constructors that just pass along to the base Exception
\r
67 /// <param name="message">Passed to Exception</param>
\r
68 /// <param name="innerException">Passed to Exception</param>
\r
70 public SqliteException(string message, Exception innerException)
\r
71 : base(message, innerException)
\r
76 /// Retrieves the underlying SQLite error code for this exception
\r
78 #if !PLATFORM_COMPACTFRAMEWORK
\r
79 public new SQLiteErrorCode ErrorCode
\r
81 public SQLiteErrorCode ErrorCode
\r
84 get { return _errorCode; }
\r
88 /// Initializes the exception class with the SQLite error code.
\r
90 /// <param name="errorCode">The SQLite error code</param>
\r
91 /// <param name="errorMessage">A detailed error message</param>
\r
92 /// <returns>An error message string</returns>
\r
93 private static string GetStockErrorMessage(int errorCode, string errorMessage)
\r
95 if (errorMessage == null) errorMessage = "";
\r
97 if (errorMessage.Length > 0)
\r
98 errorMessage = "\r\n" + errorMessage;
\r
100 if (errorCode < 0 || errorCode >= _errorMessages.Length)
\r
103 return _errorMessages[errorCode] + errorMessage;
\r
106 private static string[] _errorMessages = {
\r
109 "An internal logic error in SQLite",
\r
110 "Access permission denied",
\r
111 "Callback routine requested an abort",
\r
112 "The database file is locked",
\r
113 "A table in the database is locked",
\r
115 "Attempt to write a read-only database",
\r
116 "Operation terminated by sqlite3_interrupt()",
\r
117 "Some kind of disk I/O error occurred",
\r
118 "The database disk image is malformed",
\r
119 "Table or record not found",
\r
120 "Insertion failed because the database is full",
\r
121 "Unable to open the database file",
\r
122 "Database lock protocol error",
\r
123 "Database is empty",
\r
124 "The database schema changed",
\r
125 "Too much data for one row of a table",
\r
126 "Abort due to constraint violation",
\r
127 "Data type mismatch",
\r
128 "Library used incorrectly",
\r
129 "Uses OS features not supported on host",
\r
130 "Authorization denied",
\r
131 "Auxiliary database format error",
\r
132 "2nd parameter to sqlite3_bind() out of range",
\r
133 "File opened that is not a database file",
\r
138 /// SQLite error codes
\r
140 public enum SQLiteErrorCode
\r
147 /// SQL error or missing database
\r
151 /// Internal logic error in SQLite
\r
155 /// Access permission denied
\r
159 /// Callback routine requested an abort
\r
163 /// The database file is locked
\r
167 /// A table in the database is locked
\r
171 /// malloc() failed
\r
175 /// Attempt to write a read-only database
\r
179 /// Operation terminated by sqlite3_interrupt()
\r
183 /// Some kind of disk I/O error occurred
\r
187 /// The database disk image is malformed
\r
191 /// Table or record not found
\r
195 /// Insertion failed because database is full
\r
199 /// Unable to open the database file
\r
203 /// Database lock protocol error
\r
207 /// Database is empty
\r
211 /// The database schema changed
\r
215 /// Too much data for one row of a table
\r
219 /// Abort due to constraint violation
\r
223 /// Data type mismatch
\r
227 /// Library used incorrectly
\r
231 /// Uses OS features not supported on host
\r
235 /// Authorization denied
\r
239 /// Auxiliary database format error
\r
243 /// 2nd parameter to sqlite3_bind out of range
\r
247 /// File opened that is not a database file
\r
251 /// sqlite3_step() has another row ready
\r
255 /// sqlite3_step() has finished executing
\r