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
        ...
    }
}
Hawk
  • 5,060
  • 12
  • 49
  • 74
gdros
  • 393
  • 2
  • 10

2 Answers2

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());
}
laalto
  • 150,114
  • 66
  • 286
  • 303
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:

Community
  • 1
  • 1
voodoo98
  • 175
  • 2
  • 4