forked from jstedfast/MimeKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLiteException.cs
259 lines (244 loc) · 6.76 KB
/
SQLiteException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/********************************************************
* ADO.NET 2.0 Data Provider for SQLite Version 3.X
* Written by Robert Simpson ([email protected])
*
* Released to the public domain, use at your own risk!
********************************************************/
namespace Mono.Data.Sqlite
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
#if !PLATFORM_COMPACTFRAMEWORK
using System.Runtime.Serialization;
#endif
/// <summary>
/// SQLite exception class.
/// </summary>
#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
/// <summary>
/// Public constructor for generating a SQLite error given the base error code
/// </summary>
/// <param name="errorCode">The SQLite error code to report</param>
/// <param name="extendedInformation">Extra text to go along with the error message text</param>
public SqliteException(int errorCode, string extendedInformation)
: base(GetStockErrorMessage(errorCode, extendedInformation))
{
_errorCode = (SQLiteErrorCode)errorCode;
}
/// <summary>
/// Various public constructors that just pass along to the base Exception
/// </summary>
/// <param name="message">Passed verbatim to Exception</param>
public SqliteException(string message)
: base(message)
{
}
/// <summary>
/// Various public constructors that just pass along to the base Exception
/// </summary>
public SqliteException()
{
}
/// <summary>
/// Various public constructors that just pass along to the base Exception
/// <param name="message">Passed to Exception</param>
/// <param name="innerException">Passed to Exception</param>
/// </summary>
public SqliteException(string message, Exception innerException)
: base(message, innerException)
{
}
/// <summary>
/// Retrieves the underlying SQLite error code for this exception
/// </summary>
#if !PLATFORM_COMPACTFRAMEWORK
public new SQLiteErrorCode ErrorCode
#else
public SQLiteErrorCode ErrorCode
#endif
{
get { return _errorCode; }
}
/// <summary>
/// Initializes the exception class with the SQLite error code.
/// </summary>
/// <param name="errorCode">The SQLite error code</param>
/// <param name="errorMessage">A detailed error message</param>
/// <returns>An error message string</returns>
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",
};
}
/// <summary>
/// SQLite error codes
/// </summary>
public enum SQLiteErrorCode
{
/// <summary>
/// Success
/// </summary>
Ok = 0,
/// <summary>
/// SQL error or missing database
/// </summary>
Error,
/// <summary>
/// Internal logic error in SQLite
/// </summary>
Internal,
/// <summary>
/// Access permission denied
/// </summary>
Perm,
/// <summary>
/// Callback routine requested an abort
/// </summary>
Abort,
/// <summary>
/// The database file is locked
/// </summary>
Busy,
/// <summary>
/// A table in the database is locked
/// </summary>
Locked,
/// <summary>
/// malloc() failed
/// </summary>
NoMem,
/// <summary>
/// Attempt to write a read-only database
/// </summary>
ReadOnly,
/// <summary>
/// Operation terminated by sqlite3_interrupt()
/// </summary>
Interrupt,
/// <summary>
/// Some kind of disk I/O error occurred
/// </summary>
IOErr,
/// <summary>
/// The database disk image is malformed
/// </summary>
Corrupt,
/// <summary>
/// Table or record not found
/// </summary>
NotFound,
/// <summary>
/// Insertion failed because database is full
/// </summary>
Full,
/// <summary>
/// Unable to open the database file
/// </summary>
CantOpen,
/// <summary>
/// Database lock protocol error
/// </summary>
Protocol,
/// <summary>
/// Database is empty
/// </summary>
Empty,
/// <summary>
/// The database schema changed
/// </summary>
Schema,
/// <summary>
/// Too much data for one row of a table
/// </summary>
TooBig,
/// <summary>
/// Abort due to constraint violation
/// </summary>
Constraint,
/// <summary>
/// Data type mismatch
/// </summary>
Mismatch,
/// <summary>
/// Library used incorrectly
/// </summary>
Misuse,
/// <summary>
/// Uses OS features not supported on host
/// </summary>
NOLFS,
/// <summary>
/// Authorization denied
/// </summary>
Auth,
/// <summary>
/// Auxiliary database format error
/// </summary>
Format,
/// <summary>
/// 2nd parameter to sqlite3_bind out of range
/// </summary>
Range,
/// <summary>
/// File opened that is not a database file
/// </summary>
NotADatabase,
/// <summary>
/// sqlite3_step() has another row ready
/// </summary>
Row = 100,
/// <summary>
/// sqlite3_step() has finished executing
/// </summary>
Done = 101,
}
}