【问题标题】:ORMLite - Parenthesis in join where clausesORMLite - join where 子句中的括号
【发布时间】:2014-04-24 13:39:10
【问题描述】:

我想使用 QueryBuilder.joinQueryBuilder.joinor 连接三个表,但我希望 where 子句中的括号如下所示:

WHERE first_table_where AND (second_table_where OR third_table_where)

但这似乎是不可能的。

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

【问题讨论】:

  • 您能否描述一下您是如何以及是否能够实现这一目标的?我有完全相同的问题...我能想到的唯一解决方案是执行原始语句查询,并手动构建整个联接和 where 条件...

标签: java ormlite query-builder


【解决方案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);

【讨论】:

    猜你喜欢
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多