ORMLite - 加入 where 子句中的括号 [英] ORMLite - Parenthesis in join where clauses

查看:46
本文介绍了ORMLite - 加入 where 子句中的括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to join three tables using QueryBuilder.join and QueryBuilder.joinor but I want parenthesis in the where clause something like this:

WHERE first_table_where AND (second_table_where OR third_table_where)

但这似乎是不可能的.

也许我错过了一些东西.任何帮助将不胜感激.

Perhaps I am missing something. Any help would be appreciated.

推荐答案

我猜这是一个 您一直在寻找的文档的一部分...

如果您想线性地进行复杂查询,您甚至可以使用 Reverse Polish Notation(所有事物).有一个 Where.or(int)Where.and(int) 方法,它们对前面指定的子句进行操作.

If you want to do complex queries linearly, you can even use Reverse Polish Notation (of all things). There is a Where.or(int) and Where.and(int) methods which do the operation on the previous number of specified clauses.

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);

这篇关于ORMLite - 加入 where 子句中的括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆