下面列出了android.database.sqlite.SQLiteException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Cursor getCursorFromDB(final File dbFile, long since, int max) throws IOException {
Log.d(TAG, "using DB "+dbFile);
SQLiteDatabase db = getSqLiteDatabase(dbFile);
String limit = null;
String selection = null;
String[] selectionArgs = null;
if (since > 0) {
selection = String.format("%s > ?", TIMESTAMP);
selectionArgs = new String[]{String.valueOf(since)};
}
if (max > 0) {
limit = String.valueOf(max);
}
final String orderBy = TIMESTAMP + " ASC";
try {
return db.query(WhatsAppMessage.TABLE, null, selection, selectionArgs, null, null, orderBy, limit);
} catch (SQLiteException e) {
Log.w(TAG, "error querying DB", e);
throw new IOException("Error querying DB: "+e.getMessage());
}
}
/**
* 数据库表不存在异常
*/
private void tableException(SQLiteException sqLiteException) {
if (sqLiteException != null && sqLiteException.getMessage() != null) {
if (sqLiteException.getMessage().contains("no such table")) {
dbReset();
}
}
}
public DatabaseResult executeSQL(int databaseId, String sql) {
Log.d(TAG, "executeSQL: " + sql);
DatabaseResult result = new DatabaseResult();
IDriver driver = holders.get(databaseId).driver;
IDescriptor descriptor = holders.get(databaseId).descriptor;
try {
driver.executeSQL(descriptor, sql, result);
} catch (SQLiteException e) {
DatabaseResult.Error error = new DatabaseResult.Error();
error.code = 0;
error.message = e.getMessage();
result.sqlError = error;
}
return result;
}
public long[] getSize() {
try {
return getSizeInternal();
} catch (SQLiteException e) {
if (e.getMessage() != null && e.getMessage().contains("no such table")) {
Logger.e(TAG, "table in database not exists", e);
resetDB();
return getSizeInternal();
} else {
throw e;
}
}
}
private SQLiteDatabase getSqLiteDatabase(final File dbFile) throws IOException {
try {
return dbOpener.openDatabase(dbFile);
} catch (SQLiteException e) {
Log.w(TAG, "error opening db "+dbFile, e);
throw new IOException("Error opening database:"+e.getMessage());
}
}
public static final boolean isSQLiteDatabaseLockedException(SQLiteException e) {
String message = e.getMessage();
return !TextUtils.isEmpty(message) && message.contains("lock");
}
/**
* Determine if the exception is caused from a missing function or module in
* SQLite versions 4.2.0 and later. Lollipop uses version 3.8.4.3 so these
* are not supported in Android.
*
* @param e
* @return
*/
public static boolean isFutureSQLiteException(SQLiteException e) {
String message = e.getMessage();
return message.contains("no such function: ST_IsEmpty")
|| message.contains("no such module: rtree");
}