Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android ORMLite get query Where NOT Equal

in ORMLite document i can not find any document about this SQL command:

SELECT * FROM table WHERE state <> 1

i can get query where equal by this code:

List<ContactLists> contacts = G.CONTACTLISTSDAO.queryForEq("state","1");

how to change this code to NOT Equal


1 Answers

how to change this code to NOT Equal

The ORMLite DAO has a simple queryForEq(...) method. If you look at the code for queryForEq(...) you will see that it is just a convenience method for:

return queryBuilder().where().eq(fieldName, value).query();

This means that you can change the where to use ne(...) instead of eq(...):

return queryBuilder().where().ne(fieldName, value).query();

To do more complex queries you should RTFM about the QueryBuilder.

The QueryBuilder uses the where() method and Where class to define the WHERE portions of the query. There is eq for equals, gt for greater-than, lt for less-than, ne for not-equals, etc.. So, as @BrownKang points out, your query would be something like:

List<ContactLists> contacts =
    G.CONTACTLISTSDAO.queryBuilder().where().ne("state", "1").query();
like image 140
Gray Avatar answered May 04 '26 20:05

Gray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!