我实现了一个ContentProvider,其中SQLlite表包含以下列:
'archived'列实际上用作布尔标志,其中0是“no”,1是“yes,它已存档”。在那个数据上,我正在做两个不同的查询。
给我属于特定父级的所有元素并且不归档(parentId = xxx AND archived = 0)
public Cursor getElements(int parentId,boolean includeArchived){
Uri queryUri = MyContentProvider.CONTENT_URI;
String[] projection = new String[] { "id", "parentId", "name", "archived" };
ContentResolver cr = mContext.getContentResolver();
String where = null;
String[] whereValues = null;
if (!includeArchived) {
where = "parentId = ? AND archived = ?";
whereValues = new String[] { Integer.toString(parentId), "0" };
} else {
where = "parentId = ?";
whereValues = new String[] { Integer.toString(parentId) };
}
return cr.query(queryUri, projection, where, whereValues, null);
}
不关心archived-flag的查询有效,但另一个查询没有结果,即使archived的值在数据库中为0。我做错了什么?