24
24
//--------------------------------------
25
25
package org .sqlite ;
26
26
27
+ import java .sql .SQLException ;
28
+
27
29
/**
28
30
* SQLite3 error code
29
31
*
@@ -63,7 +65,53 @@ public enum SQLiteErrorCode {
63
65
SQLITE_RANGE (25 , " 2nd parameter to sqlite3_bind out of range" ),
64
66
SQLITE_NOTADB (26 , " File opened that is not a database file" ),
65
67
SQLITE_ROW (100 , " sqlite3_step() has another row ready" ),
66
- SQLITE_DONE (101 , " sqlite3_step() has finished executing" );
68
+ SQLITE_DONE (101 , " sqlite3_step() has finished executing" ),
69
+ /* Beginning of extended error codes */
70
+ SQLITE_BUSY_RECOVERY (261 , " Another process is busy recovering a WAL mode database file following a crash" ),
71
+ SQLITE_LOCKED_SHAREDCACHE (262 , " Contention with a different database connection that shares the cache" ),
72
+ SQLITE_READONLY_RECOVERY (264 , " The database file needs to be recovered" ),
73
+ SQLITE_IOERR_READ (266 , " I/O error in the VFS layer while trying to read from a file on disk" ),
74
+ SQLITE_CORRUPT_VTAB (267 , " Content in the virtual table is corrupt" ),
75
+ SQLITE_CONSTRAINT_CHECK (275 , " A CHECK constraint failed" ),
76
+ SQLITE_ABORT_ROLLBACK (516 , " The transaction that was active when the SQL statement first started was rolled back" ),
77
+ SQLITE_BUSY_SNAPSHOT (517 , " Another database connection has already written to the database" ),
78
+ SQLITE_READONLY_CANTLOCK (520 , " The shared-memory file associated with that database is read-only" ),
79
+ SQLITE_IOERR_SHORT_READ (522 , " The VFS layer was unable to obtain as many bytes as was requested" ),
80
+ SQLITE_CANTOPEN_ISDIR (526 , " The file is really a directory" ),
81
+ SQLITE_CONSTRAINT_COMMITHOOK (531 , " A commit hook callback returned non-zero" ),
82
+ SQLITE_READONLY_ROLLBACK (776 , " Hot journal needs to be rolled back" ),
83
+ SQLITE_IOERR_WRITE (778 , " I/O error in the VFS layer while trying to write to a file on disk" ),
84
+ SQLITE_CANTOPEN_FULLPATH (782 , " The operating system was unable to convert the filename into a full pathname" ),
85
+ SQLITE_CONSTRAINT_FOREIGNKEY (787 , " A foreign key constraint failed" ),
86
+ SQLITE_READONLY_DBMOVED (1032 , " The database file has been moved since it was opened" ),
87
+ SQLITE_IOERR_FSYNC (1034 , " I/O error in the VFS layer while trying to flush previously written content" ),
88
+ SQLITE_CANTOPEN_CONVPATH (1038 , " cygwin_conv_path() system call failed while trying to open a file" ),
89
+ SQLITE_CONSTRAINT_FUNCTION (1043 , " Error reported by extension function" ),
90
+ SQLITE_IOERR_DIR_FSYNC (1290 , " I/O error in the VFS layer while trying to invoke fsync() on a directory" ),
91
+ SQLITE_CONSTRAINT_NOTNULL (1299 , " A NOT NULL constraint failed" ),
92
+ SQLITE_IOERR_TRUNCATE (1546 , " I/O error in the VFS layer while trying to truncate a file to a smaller size" ),
93
+ SQLITE_CONSTRAINT_PRIMARYKEY (1555 , " A PRIMARY KEY constraint failed" ),
94
+ SQLITE_IOERR_FSTAT (1802 , " I/O error in the VFS layer while trying to invoke fstat()" ),
95
+ SQLITE_CONSTRAINT_TRIGGER (1811 , " A RAISE function within a trigger fired, causing the SQL statement to abort" ),
96
+ SQLITE_IOERR_UNLOCK (2058 , " I/O error within xUnlock" ),
97
+ SQLITE_CONSTRAINT_UNIQUE (2067 , " A UNIQUE constraint failed" ),
98
+ SQLITE_IOERR_RDLOCK (2314 , " I/O error within xLock" ),
99
+ SQLITE_CONSTRAINT_VTAB (2323 , " Error reported by application-defined virtual table" ),
100
+ SQLITE_IOERR_DELETE (2570 , " I/O error within xDelete" ),
101
+ SQLITE_CONSTRAINT_ROWID (2579 , " rowid is not unique" ),
102
+ SQLITE_IOERR_NOMEM (3082 , " Unable to allocate sufficient memory" ),
103
+ SQLITE_IOERR_ACCESS (3338 , " I/O error within the xAccess" ),
104
+ SQLITE_IOERR_CHECKRESERVEDLOCK (3594 , " I/O error within xCheckReservedLock" ),
105
+ SQLITE_IOERR_LOCK (3850 , " I/O error in the advisory file locking logic" ),
106
+ SQLITE_IOERR_CLOSE (4106 , " I/O error within xClose" ),
107
+ SQLITE_IOERR_SHMOPEN (4618 , " I/O error within xShmMap while trying to open a new shared memory segment" ),
108
+ SQLITE_IOERR_SHMSIZE (4874 , " I/O error within xShmMap while trying to resize an existing shared memory segment" ),
109
+ SQLITE_IOERR_SHMMAP (5386 , " I/O error within xShmMap while trying to map a shared memory segment" ),
110
+ SQLITE_IOERR_SEEK (5642 , " I/O error while trying to seek a file descriptor" ),
111
+ SQLITE_IOERR_DELETE_NOENT (5898 , " The file being deleted does not exist" ),
112
+ SQLITE_IOERR_MMAP (6154 , " I/O error while trying to map or unmap part of the database file" ),
113
+ SQLITE_IOERR_GETTEMPPATH (6410 , " Unable to determine a suitable directory in which to place temporary files" ),
114
+ SQLITE_IOERR_CONVPATH (6666 , " cygwin_conv_path() system call failed" );
67
115
68
116
public final int code ;
69
117
public final String message ;
@@ -85,14 +133,29 @@ private SQLiteErrorCode(int code, String message)
85
133
*/
86
134
public static SQLiteErrorCode getErrorCode (int errorCode )
87
135
{
136
+ return fromVendorCode (errorCode );
137
+ }
138
+
139
+ public static SQLiteErrorCode fromVendorCode (int vendorCode ) {
88
140
for (SQLiteErrorCode each : SQLiteErrorCode .values ())
89
141
{
90
- if (errorCode == each .code )
142
+ if (vendorCode == each .code )
91
143
return each ;
92
144
}
93
145
return UNKNOWN_ERROR ;
94
146
}
95
147
148
+ public static SQLiteErrorCode fromException (SQLException e ) {
149
+ return fromVendorCode (e .getErrorCode ());
150
+ }
151
+
152
+ public int toVendorCode (boolean useExtendedResultCodes ) {
153
+ if (useExtendedResultCodes ) {
154
+ return code ;
155
+ }
156
+ return code & 0xff ;
157
+ }
158
+
96
159
/**
97
160
* @see java.lang.Enum#toString()
98
161
*/
0 commit comments