I have a TEXT column and I want to match all rows where the value has
a certain prefix. For example,

WHERE mycol LIKE 'myprefix%'

However, I noticed in some optimization guidelines that this will not
use the index and instead you should do this:

WHERE mycol >= 'myprefix' AND mycol < 'myprefiy'

Instead of simple A-Z chars, I have a whole variety of UTF-8 chars
(think chinese characters).

My question is, how to work out the next char in UTF-8?

Is it enough to add one to the codepoint, such as:

String lowerBound = "myprefix";
int codepoint = Character.codePointAt(lowerBound, lowerBound.length()
- 1);
String upperBound = lowerBound.substring(0, lowerBound.length() - 1) +
Character.toChars(codePoint + 1);
String sql = "SELECT * FROM mytable WHERE mycol >= '" + lowerBound +
'" AND mycol < '" + upperBoundPrefix + "'"

?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to