简体   繁体   中英

SQLite query less than or greater than check

I want to use this:

return mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, 
KEY_LEVEL }, KEY_LEVEL + ">= 3 AND " + KEY_LEVEL + " < 5", null, null, null, null);

But instead of 5 I want it to check the next column where it finds greater than or equal to three.

So when I give an input of say 5, I want it to check for greater than or equal to 5 in column 3 but less than the value in the next column, column 4.

Original code taken from Sqlite query check - less than and greater than .

Just do this :

String[] selectionArgs = { "5", "5" };
String[] columns = { KEY_ROWID, KEY_COLUMN3, KEY_COLUMN4 };
String selection = "KEY_COLUMN3 >= ? AND KEY_COLUMN4 < ?";
return mDb.query(DATABASE_TABLE, columns, selection, selectionArgs, null, null, null);

For me just passing numerics in String format like @buzeeg offered didn't work .

PROBLEM: My task was to perform UPDATE and in my case it should not have succeed, but as you may guess, when we use 1 as query arg, '1'>2 means true :

UPDATE table SET field = 1 WHERE ? > 2

SOLUTION: CAST helped me to solve it:

SELECT * FROM smth WHERE CAST(? as integer) > 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM