0

My question is related to sqlite syntax for android. I have a query in which I want to fetch some data that has a key value in bigger level than the given. For example the given id is 134.2 and the records tha will be fetched are like these 134.2.5 or 134.2.98. The problem is that I lose something in the syntax and I get nothing as a result. Here is my code. Thank you in advance.

I hope this help. SELECT * FROM TASKS WHERE FATHER_ID= FID+"."+"%"+"."

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
            KEY_BODY,KEY_location  , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER, KEY_TODAY, KEY_NOTIFY,KEY_NUMBER_OF_DAYS, KEY_NOTICE_CHECK }, KEY_FATHER + " LIKE " + "'"+ id+"'"+"'"+".'"+"'" +"%'"+"'"+".'", null, null, null, null);

3 Answers 3

2

The way you are constructing the key comparision expression seems overly complex; also it should be a query parameter so you don't worry about quoting so much:

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
            KEY_BODY,KEY_location  , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER, KEY_TODAY, KEY_NOTIFY,KEY_NUMBER_OF_DAYS, KEY_NOTICE_CHECK }, KEY_FATHER + " LIKE ?", new String[] { id + ".%" }, null, null, null);
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe you can add to the question a SELECT statement that retrieves what you want from your database, so we can see what you are trying to end up with in your mDb query.
0

Try replacing

+ " LIKE " + "'"+ id+"'"+"'"+".'"+"'" +"%'"+"'"+".'"

with

+ " LIKE " + "'" + id + ".%'"

Comments

0

Maybe you wanted this:

mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
            KEY_BODY,KEY_location  , KEY_GOAL_DATE,KEY_ABSOLUTE_DATE, KEY_DATE_CURRENT ,KEY_PRIO,KEY_DONE, KEY_CATEGORY,KEY_TIME_SPEND,KEY_POSOSTO, KEY_FATHER, KEY_TODAY, KEY_NOTIFY,KEY_NUMBER_OF_DAYS, KEY_NOTICE_CHECK },KEY_FATHER + " LIKE " + "'"+ id+".%'", null, null, null, null);

1 Comment

thank you vrery much,but i still get nothing. the only way that gave me result nto the correct one, was "'"+id+"%'", because it included records that i dont need. for example 134.2.3.4.i want only one level further from where I am

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.