OrmLite: 如何在AND/OR条件中构建WHERE NOT子句

3
我想在OrmLite中表达以下SQL查询:
SELECT * FROM table WHERE NOT (number1 = 0 AND number2 = 0)

这里的问题是要在非操作中包装一个AND条件。
  • My first assumption was to write:

    queryBuilder().
       where().not()
          .eq("number1", 0)
          .and()
          .eq("number2", 0);
    

    Result:

    SELECT * FROM table WHERE ((NOT number1 = 0 ) AND number2 = 0)
    
  • Next approach:

    queryBuilder().
       where().not()
          .eq("number1", 0)
          .and().not()
          .eq("number2", 0);
    

    Result:

    SELECT * FROM table WHERE ((NOT number1 = 0 ) AND (NOT number2 = 0) )
    
  • Finally I tried:

    queryBuilder.where()
       .not(
          where.eq(DbProperties.COLUMN_NAME_GROUP_ID, item.groupId)
             .and().eq(DbProperties.COLUMN_NAME_TASK_ID, item.taskId)
       );
    

    Result:

    IllegalArgumentException: NOT operation can only work with comparison SQL clauses
    
我也了解方法。
and(int numClause) 
or(int numClause)

但是OrmLite没有提供
not(int numClause).

有没有其他方法可以构建查询?

1个回答

0
SELECT * FROM table WHERE NOT (number1 = 0 AND number2 = 0)

等同于

SELECT * FROM table WHERE ((NOT number1 = 0 ) OR (NOT number2 = 0) )  

重新排列您之前的查询,应该是:

queryBuilder().
   where()
      .not().eq("number1", 0)
      .or()
      .not().eq("number2", 0);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接