@@ -33,24 +33,25 @@ void throw_sqlite3_exception(JNIEnv* env, const char* message) {
3333 */
3434void throw_sqlite3_exception (JNIEnv* env, sqlite3* handle, const char * message) {
3535 if (handle) {
36- throw_sqlite3_exception (env, sqlite3_errcode (handle),
37- sqlite3_errmsg (handle), message);
36+ // get the error code and message from the SQLite connection
37+ // the error message may contain more information than the error code
38+ // because it is based on the extended error code rather than the simplified
39+ // error code that SQLite normally returns.
40+ throw_sqlite3_exception (env, sqlite3_errcode (handle), sqlite3_errmsg (handle), message);
3841 } else {
3942 // we use SQLITE_OK so that a generic SQLiteException is thrown;
4043 // any code not specified in the switch statement below would do.
4144 throw_sqlite3_exception (env, SQLITE_OK, " unknown error" , message);
4245 }
4346}
4447
45- /* throw a SQLiteException for a given error code */
48+ /* throw a SQLiteException for a given error code
49+ * should only be used when the database connection is not available because the
50+ * error information will not be quite as rich */
4651void throw_sqlite3_exception_errcode (JNIEnv* env, int errcode, const char * message) {
47- if (errcode == SQLITE_DONE) {
48- throw_sqlite3_exception (env, errcode, NULL , message);
49- } else {
50- char temp[21 ];
51- sprintf (temp, " error code %d" , errcode);
52- throw_sqlite3_exception (env, errcode, temp, message);
53- }
52+ char temp[21 ];
53+ sprintf (temp, " error code %d" , errcode);
54+ throw_sqlite3_exception (env, errcode, temp, message);
5455}
5556
5657/* throw a SQLiteException for a given error code, sqlite3message, and
@@ -75,6 +76,7 @@ void throw_sqlite3_exception(JNIEnv* env, int errcode,
7576 break ;
7677 case SQLITE_DONE:
7778 exceptionClass = " android/database/sqlite/SQLiteDoneException" ;
79+ sqlite3Message = NULL ; // SQLite error message is irrelevant in this case
7880 break ;
7981 case SQLITE_FULL:
8082 exceptionClass = " android/database/sqlite/SQLiteFullException" ;
0 commit comments