当使用for循环生成条件时,如何在ormlite中编写查询
我正在 ormlite 中编写一个查询,如下所示
Where<Advertisement, Integer> where = queryBuilder.where();
where.and(
where.between("latitude", pLatitude - APPOXIMATION_FACTOR,
pLatitude + APPOXIMATION_FACTOR),
where.between("longitude", pLongitude - APPOXIMATION_FACTOR,
pLongitude + APPOXIMATION_FACTOR)
.and().between("width", pWidth - APPOXIMATION_FACTOR,
pWidth + APPOXIMATION_FACTOR),
);
,还有一个查询
for (int iterator = 0; iterator < moduleList.size(); iterator++) {
where.eq("id", moduleList.get(iterator).getmId());
if (iterator != advertisementList.size() - 1){
whereForModuleID.or();
}
}
,但我无法在这种情况下编写查询
寻求帮助
I'm writing a query in ormlite as below
Where<Advertisement, Integer> where = queryBuilder.where();
where.and(
where.between("latitude", pLatitude - APPOXIMATION_FACTOR,
pLatitude + APPOXIMATION_FACTOR),
where.between("longitude", pLongitude - APPOXIMATION_FACTOR,
pLongitude + APPOXIMATION_FACTOR)
.and().between("width", pWidth - APPOXIMATION_FACTOR,
pWidth + APPOXIMATION_FACTOR),
);
and also one more and with this
for (int iterator = 0; iterator < moduleList.size(); iterator++) {
where.eq("id", moduleList.get(iterator).getmId());
if (iterator != advertisementList.size() - 1){
whereForModuleID.or();
}
}
but i am stuck how to write query in this case
Looking for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第二种情况下,我会使用 where.in(String, Iterable) 方法。你应该这样做:
这会变成一个 SQL 查询,如下所示:
这是关于
where.in()
的文档:就原始问题而言,请参阅此有关
where.and(int)
和or(int)
方法。In the 2nd case I'd use instead the where.in(String, Iterable) method. You should do something like this:
This turns into a SQL query like:
Here are the docs on
where.in()
:In terms of the original question, see this answer about the
where.and(int)
andor(int)
methods.要创建一个按名称和密码查找帐户的查询,您需要执行以下操作:
这是我在项目中使用的代码,使用 ORMLite 从 SQLite 获取 PropertyModel
在此示例中,将生成的 SQL 查询将是大约:
https://github.com/AshishPsaini/ormlite-examples/tree/master/android/HelloAndroid
http://ormlite.com/docs/in
To create a query which looks up an account by name and password you would do the following:
This is my code which i am using in my project to get PropertyModel from SQLite using ORMLite
In this example, the SQL query that will be generated will be approximately:
https://github.com/AshishPsaini/ormlite-examples/tree/master/android/HelloAndroid
http://ormlite.com/docs/in