ORMLite - 连接where子句中的括号

时间:2014-04-24 13:39:10

标签: java ormlite query-builder

我想使用QueryBuilder.joinQueryBuilder.joinor加入三个表,但我想在where子句中使用括号:

WHERE first_table_where AND (second_table_where OR third_table_where)

但似乎这是不可能的。

也许我错过了什么。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

我想这是你一直在寻找的part of the doc ......

  

如果你想线性地进行复杂查询,你甚至可以使用反向波兰表示法(所有东西)。有一个Where.or(int)Where.and(int)方法可以对前面指定的子句进行操作。

where.eq(Account.NAME_FIELD_NAME, "foo");
where.eq(Account.PASSWORD_FIELD_NAME, "_secret");
// this does an AND between the previous 2 clauses
// it also puts a clause back on the stack
where.and(2);
where.eq(Account.NAME_FIELD_NAME, "bar"),
where.eq(Account.PASSWORD_FIELD_NAME, "qwerty")));
// this does an AND between the previous 2 clauses
// it also puts a clause back on the stack
where.and(2);
// this does an OR between the previous 2 AND clauses
where.or(2);
相关问题