这是一个 ORMLite 错误吗?
Is this an ORMLite bug?
Where
API 4.48 中有一个使用 where
子句的示例,完全像这样:
QueryBuilder<Account, String> qb = accountDao.queryBuilder();
Where where = qb.where();
// the name field must be equal to "foo"
where.eq(Account.NAME_FIELD_NAME, "foo");
// and
where.and();
// the password field must be equal to "_secret"
where.eq(Account.PASSWORD_FIELD_NAME, "_secret");
PreparedQuery<Account, String> preparedQuery = qb.prepareQuery();
但这对我不起作用 (java.lang.IllegalStateException: No where clauses defined
) 除非我这样做:
qb.setWhere(where);
在准备查询之前。当 API 建议它应该这样做时,内部 where
对象似乎没有发生变化。
有没有其他人有过同样的经历?
更新
看起来甚至连调用 setWhere()
都不行。我不知何故把我的试验搞砸了。
我发现了问题,这是我的错。在调试时,我多次在 QueryBuilder
对象上调用 where()
。但是,正如 where
方法的文档所述:
public Where<T,ID> where()
Returns a Where object that should be used to add SQL where clauses to the statement. This will also reset the where object so you can use the same query builder with a different where statement.
正在重置内部 where
对象。
Where
API 4.48 中有一个使用 where
子句的示例,完全像这样:
QueryBuilder<Account, String> qb = accountDao.queryBuilder();
Where where = qb.where();
// the name field must be equal to "foo"
where.eq(Account.NAME_FIELD_NAME, "foo");
// and
where.and();
// the password field must be equal to "_secret"
where.eq(Account.PASSWORD_FIELD_NAME, "_secret");
PreparedQuery<Account, String> preparedQuery = qb.prepareQuery();
但这对我不起作用 (java.lang.IllegalStateException: No where clauses defined
) 除非我这样做:
qb.setWhere(where);
在准备查询之前。当 API 建议它应该这样做时,内部 where
对象似乎没有发生变化。
有没有其他人有过同样的经历?
更新
看起来甚至连调用 setWhere()
都不行。我不知何故把我的试验搞砸了。
我发现了问题,这是我的错。在调试时,我多次在 QueryBuilder
对象上调用 where()
。但是,正如 where
方法的文档所述:
public Where<T,ID> where()
Returns a Where object that should be used to add SQL where clauses to the statement. This will also reset the where object so you can use the same query builder with a different where statement.
正在重置内部 where
对象。