0

I am making a search function and I need to search using two inputs:

  1. the category id (CID) it is a string that is contained (or not) in KEY_P_CAT_LIST (it cant be done with = as it usually isn't equal)

  2. the search text input (input)

I need to check if the category and the input text is contained in the db record and return it in a cursor if so.

coloane is correctly defined as a [] String and is not the problem.

My atempt:

db.query(true, P_TABLE, coloane,KEY_P_CAT_LIST + " LIKE " + " AND " +CID + " LIKE", new String[] {"%"+CID+"%", "%"+input+"%"}, null, null, null, null);

0

1 Answer 1

1

Try this:

db.query(true, P_TABLE, coloane,KEY_P_CAT_LIST + " LIKE ?" + " AND " +CID + " LIKE ?", new String[] {"%"+CID+"%", "%"+input+"%"}, null, null, null, null);

Hope it Helps!!

Sign up to request clarification or add additional context in comments.

4 Comments

It is not crashing anymore but gives no results when I give it an input, but if the input is empty it works but shows all products in the category
actually it works, I had to add KEY_P_NAME instead of CID Thanks a lot.
"Like" is case sensitive in SQLite. so i hope you have checked the input string and db data has no differences Case wise.
when it compares the input to the database value it is not case sensitive: if I add aqua and the value is Aqua it still works. I will have to take in consideration multiple inputs such as "laptop asus" and search for each word separately then sort result by relevance but I'm just making a demo so that's for a later time.

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.