2 // Mono.Data.Sqlite.SQLiteException.cs
5 // Robert Simpson (robert@blackcastlesoft.com)
7 // Adapted and modified for the Mono Project by
8 // Marek Habersack (grendello@gmail.com)
11 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
12 // Copyright (C) 2007 Marek Habersack
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 /********************************************************
35 * ADO.NET 2.0 Data Provider for Sqlite Version 3.X
36 * Written by Robert Simpson (robert@blackcastlesoft.com)
38 * Released to the public domain, use at your own risk!
39 ********************************************************/
41 namespace Mono
.Data
.Sqlite
44 using System
.Collections
.Generic
;
46 using System
.Data
.Common
;
48 #if !PLATFORM_COMPACTFRAMEWORK
49 using System
.Runtime
.Serialization
;
53 /// Sqlite exception class.
55 #if !PLATFORM_COMPACTFRAMEWORK
57 public class SqliteException
: DbException
59 public class SqliteException
: Exception
62 private SqliteErrorCode _errorCode
;
64 #if !PLATFORM_COMPACTFRAMEWORK
65 private SqliteException(SerializationInfo info
, StreamingContext context
)
72 /// Public constructor for generating a Sqlite error given the base error code
74 /// <param name="errorCode">The Sqlite error code to report</param>
75 /// <param name="extendedInformation">Extra text to go along with the error message text</param>
76 public SqliteException(int errorCode
, string extendedInformation
)
77 : base(GetStockErrorMessage(errorCode
, extendedInformation
))
79 _errorCode
= (SqliteErrorCode
)errorCode
;
83 /// Various public constructors that just pass along to the base Exception
85 /// <param name="message">Passed verbatim to Exception</param>
86 public SqliteException(string message
)
92 /// Various public constructors that just pass along to the base Exception
94 public SqliteException()
99 /// Various public constructors that just pass along to the base Exception
100 /// <param name="message">Passed to Exception</param>
101 /// <param name="innerException">Passed to Exception</param>
103 public SqliteException(string message
, Exception innerException
)
104 : base(message
, innerException
)
109 /// Retrieves the underlying Sqlite error code for this exception
111 #if !PLATFORM_COMPACTFRAMEWORK
112 public new SqliteErrorCode ErrorCode
114 public SqliteErrorCode ErrorCode
117 get { return _errorCode; }
121 /// Initializes the exception class with the Sqlite error code.
123 /// <param name="errorCode">The Sqlite error code</param>
124 /// <param name="errorMessage">A detailed error message</param>
125 /// <returns>An error message string</returns>
126 private static string GetStockErrorMessage(int errorCode
, string errorMessage
)
128 if (errorMessage
== null) errorMessage
= "";
130 if (errorMessage
.Length
> 0)
131 errorMessage
= "\r\n" + errorMessage
;
133 if (errorCode
< 0 || errorCode
>= _errorMessages
.Length
)
136 return _errorMessages
[errorCode
] + errorMessage
;
139 private static string[] _errorMessages
= {
142 "An internal logic error in Sqlite",
143 "Access permission denied",
144 "Callback routine requested an abort",
145 "The database file is locked",
146 "A table in the database is locked",
148 "Attempt to write a read-only database",
149 "Operation terminated by sqlite3_interrupt()",
150 "Some kind of disk I/O error occurred",
151 "The database disk image is malformed",
152 "Table or record not found",
153 "Insertion failed because the database is full",
154 "Unable to open the database file",
155 "Database lock protocol error",
157 "The database schema changed",
158 "Too much data for one row of a table",
159 "Abort due to constraint violation",
160 "Data type mismatch",
161 "Library used incorrectly",
162 "Uses OS features not supported on host",
163 "Authorization denied",
164 "Auxiliary database format error",
165 "2nd parameter to sqlite3_bind() out of range",
166 "File opened that is not a database file",
171 /// Sqlite error codes
173 public enum SqliteErrorCode
180 /// SQL error or missing database
184 /// Internal logic error in Sqlite
188 /// Access permission denied
192 /// Callback routine requested an abort
196 /// The database file is locked
200 /// A table in the database is locked
208 /// Attempt to write a read-only database
212 /// Operation terminated by sqlite3_interrupt()
216 /// Some kind of disk I/O error occurred
220 /// The database disk image is malformed
224 /// Table or record not found
228 /// Insertion failed because database is full
232 /// Unable to open the database file
236 /// Database lock protocol error
240 /// Database is empty
244 /// The database schema changed
248 /// Too much data for one row of a table
252 /// Abort due to constraint violation
256 /// Data type mismatch
260 /// Library used incorrectly
264 /// Uses OS features not supported on host
268 /// Authorization denied
272 /// Auxiliary database format error
276 /// 2nd parameter to sqlite3_bind out of range
280 /// File opened that is not a database file
284 /// sqlite3_step() has another row ready
288 /// sqlite3_step() has finished executing