Java 类android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException 实例源码

项目:aelf-dailyreadings    文件:AelfCacheHelper.java   
private void onSqliteError(SQLiteException e) {
    if (
        e instanceof SQLiteBindOrColumnIndexOutOfRangeException ||
        e instanceof SQLiteConstraintException ||
        e instanceof SQLiteDatabaseCorruptException ||
        e instanceof SQLiteDatatypeMismatchException
    ) {
        // If a migration did not go well, the best we can do is drop the database and re-create
        // it from scratch. This is hackish but should allow more or less graceful recoveries.
        TrackHelper.track().event("Office", "cache.db.error").name("critical").value(1f).with(tracker);
        Log.e(TAG, "Critical database error. Droping + Re-creating", e);
        close();
        ctx.deleteDatabase(DB_NAME);
    } else {
        // Generic error. Close + re-open
        Log.e(TAG, "Datable "+e.getClass().getName()+". Closing + re-opening", e);
        TrackHelper.track().event("Office", "cache.db.error").name(e.getClass().getName()).value(1f).with(tracker);
        close();
    }
}
项目:sqlite-android    文件:SQLiteConnection.java   
private void bindArguments(PreparedStatement statement, Object[] bindArgs) {
    final int count = bindArgs != null ? bindArgs.length : 0;
    if (count != statement.mNumParameters) {
        String message = "Expected " + statement.mNumParameters + " bind arguments but "
            + count + " were provided.";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            throw new SQLiteBindOrColumnIndexOutOfRangeException(message);
        } else {
            throw new SQLiteException(message);
        }
    }
    if (count == 0) {
        return;
    }

    final long statementPtr = statement.mStatementPtr;
    for (int i = 0; i < count; i++) {
        final Object arg = bindArgs[i];
        switch (getTypeOfObject(arg)) {
            case Cursor.FIELD_TYPE_NULL:
                nativeBindNull(mConnectionPtr, statementPtr, i + 1);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                nativeBindLong(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).longValue());
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                nativeBindDouble(mConnectionPtr, statementPtr, i + 1,
                        ((Number)arg).doubleValue());
                break;
            case Cursor.FIELD_TYPE_BLOB:
                nativeBindBlob(mConnectionPtr, statementPtr, i + 1, (byte[])arg);
                break;
            case Cursor.FIELD_TYPE_STRING:
            default:
                if (arg instanceof Boolean) {
                    // Provide compatibility with legacy applications which may pass
                    // Boolean values in bind args.
                    nativeBindLong(mConnectionPtr, statementPtr, i + 1, (Boolean) arg ? 1 : 0);
                } else {
                    nativeBindString(mConnectionPtr, statementPtr, i + 1, arg.toString());
                }
                break;
        }
    }
}