Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Query : Select Query with BETWEEN clause

I want to run this query in Android Application :

SELECT field1 FROM table1  
where field1 = ?(enteredField1) AND field2 = ?(enteredField2)  
AND enteredField3 BETWEEN field3 , field4  
;

my DB schema

table1(field1, field2, field3, field4, field5)  

enteredField1 , 2 , 3 = are parameters which is to be checked.

I hope I am clear with my question.

here is the function -

public boolean checkData(String task1, String dte1, String startTime1 )  
{   

        // field 1 = task , fiels 2 = dte, field 3 = startHr, field 4 = endHr  
        // enteredField 1,2,3 = task1, dte1, startTime1   
        // here I want to insert the query  

    int a = cursor.getCount();  
    if(a>0)  
    {  
        return true;  
    }  
    return false;  
}  
like image 606
sid Avatar asked Jan 21 '23 08:01

sid


1 Answers

First, your query is invalid. There is no INBETWEEN in SQL; use BETWEEN:

... test_expr BETWEEN lower_bound_expr AND upper_bound_expr

Also, the comma is not a binary operator that works in WHERE clauses; use AND instead:

... WHERE binary_expression_1 AND binary_expression_2

Execute the query with one of the query methods in SQLiteDatabase. Which you use depends on your needs; the one I linked to is probably fine for yours.

like image 123
Blrfl Avatar answered Jan 28 '23 22:01

Blrfl