0

I have a row in mytable with this value '{"test":"Hello World"}' in column1.

If I search the database with

SELECT * 
FROM mytable 
WHERE column1 LIKE '%Hello World%'

I get nothing. If I change the query to

SELECT * 
FROM mytable 
WHERE column1 LIKE '%Hello%'.

I get results but this is not what I want because this returns unwanted rows.

Is something wrong with the space character between the two words?

My code looks like this:

Cursor cursor=db.rawQuery("SELECT * FROM mytable WHERE column1 LIKE '%Hello World%'",null);
if(cursor.moveToFirst()) {
    while(cursor.moveToNext()) {
        //log results
        ...
    }
}
3
  • Go to this link: http://thinkdiff.net/mixed/sqlite-space-within-string/ for just information Commented Feb 25, 2014 at 11:38
  • Try that query in sqlite browser and see the results are coming or not.. Commented Feb 25, 2014 at 11:43
  • I already did that and it works... Commented Feb 25, 2014 at 11:48

2 Answers 2

1
if(cursor.moveToFirst()) {
    while(cursor.moveToNext()) {

Code like this will skip the first row. Instead, do it like this:

if (cursor.moveToFirst()) {
    do {
        //...
    } while (cursor.moveToNext());
}
Sign up to request clarification or add additional context in comments.

Comments

0

First of all the

SELECT * FROM mytable WHERE column1 LIKE '%Hello World%'

works for me in SQLite Database Browser (http://portableapps.com/apps/development/sqlite_database_browser_portable).

you can use the trim function as well:

Comments

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.