Java Code Examples for android.database.sqlite.SQLiteException#getMessage()

The following examples show how to use android.database.sqlite.SQLiteException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Whassup.java    From whassup with Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example 2
Source File: AnsContentProvider.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 数据库表不存在异常
 */
private void tableException(SQLiteException sqLiteException) {
    if (sqLiteException != null && sqLiteException.getMessage() != null) {
        if (sqLiteException.getMessage().contains("no such table")) {
            dbReset();
        }
    }
}
 
Example 3
Source File: Databases.java    From pandora with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: FileCache.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
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;
        }
    }
}
 
Example 5
Source File: Whassup.java    From whassup with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example 6
Source File: DatabaseHelper.java    From RxZhihuDaily with MIT License 4 votes vote down vote up
public static final boolean isSQLiteDatabaseLockedException(SQLiteException e) {
    String message = e.getMessage();

    return !TextUtils.isEmpty(message) && message.contains("lock");
}
 
Example 7
Source File: TestUtils.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * 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");
}