我正在使用内容提供商。 Content Provider使用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;
}
这是我得到的完整错误:
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结合起来,有人能举例说明吗?
答案 0 :(得分:2)
if(uriMatcher.match(uri) == ANIMAL_RID) {
sqlBuilder.appendWhere("rid = ?");
selectionArgs = new String[] {uri.getPathSegments().get(1)};
}
这很有效。没有更多缓存错误。