Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite LIKE escape wildcard

On Android Jellybean 4.1 is it possible to escape a LIKE wildcard character and still have the like use the index?

Use:

where field like 'xyz\_abc'

as opposed to:

where field like 'xyz_abc'

Does escaping wildcards work on Android? And will it still use the index if the wildcard is escaped?

What I am currently doing is:

where field like 'xyz_abc' and lower(field) = lower('xyz_abc')

Which is horribly inefficient due to the wildcard character.

Thanks

like image 819
Rowan Smith Avatar asked Dec 11 '12 23:12

Rowan Smith


1 Answers

You need to use the ESCAPE clause:

where field like 'xyz\_abc' escape '\'

See the section The LIKE and GLOB operators in the SQLite Documentation.

like image 174
Brigham Avatar answered Oct 01 '22 07:10

Brigham