开发者

Content Provider MAX size compiled-sql statement

I'm using Content Providers. The Content Provider uses SQLBuilder:

public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();
    sqlBuilder.setTables(TABLE_NAME);

    if(uriMatcher.match(uri) == ANIMAL_ID)
        sqlBuilder.appendWhere(ID + " = " + uri.getPathSegments().get(0));

    if(uriMatcher.match(uri) == ANIMAL_PID)
        sqlBuilder.appendWhere(PID + " = " + uri.getPathSegments().get(1));

    if(uriMatcher.match(uri) == ANIMAL_NAME)
        sqlBuilder.appendWhere(NAME + " = " + uri.getPathSegments().get(1));

    if(uriMatcher.match(uri) == ANIMAL_RID)
        sqlBuilder.appendWhere("rid = " + uri.getPathSegments().get(1));

    if(sortOrder == null || sortOrder == "")
        sortOrder = "naam";

    Cursor c = sqlBuilder.query(animalDB, projection, selection, selectionArgs, null, null, sortOrder);
    c.setNotificationUri(getContext().getContentResolver(), uri);

    return c;
}

This is the full error I get:

05-30 12:36:43.56开发者_StackOverflow社区4: WARN/Database(6746): Reached MAX size for compiled-sql statement cache for database /data/data/nl.actinum.labbook/databases/blue4green; i.e., NO space for this sql statement in cache: SELECT * FROM dier WHERE (rid = 84) ORDER BY naam. Please change your sql statements to use '?' for bindargs, instead of using actual values

Its unclear to me how I can combine the question marks with the SQLBuilder, can someone show my an example?


if(uriMatcher.match(uri) == ANIMAL_RID) {
        sqlBuilder.appendWhere("rid = ?");
        selectionArgs = new String[] {uri.getPathSegments().get(1)};
    }

This works. No more cache errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜