内容提供者MAX大小,已编译的sql语句

问题描述

| 我正在使用内容提供商。内容提供者使用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,sortOrder);
    c.setNotificationUri(getContext().getContentResolver(),uri);

    return c;
}
这是我得到的完整错误
05-30 12:36:43.564: 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
我不清楚如何将问号与sqlBuilder结合使用,有人可以举一个例子吗?     

解决方法

        
if(uriMatcher.match(uri) == ANIMAL_RID) {
        sqlBuilder.appendWhere(\"rid = ?\");
        selectionArgs = new String[] {uri.getPathSegments().get(1)};
    }
这可行。没有更多的缓存错误。