user1347280
user1347280

Reputation: 85

String query in sqlite, android

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);

Upvotes: 0

Views: 148

Answers (3)

gezimi005
gezimi005

Reputation: 381

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);

Upvotes: 0

antlersoft
antlersoft

Reputation: 14786

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);

Upvotes: 2

Geobits
Geobits

Reputation: 22342

Try replacing

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

with

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

Upvotes: 0

Related Questions