Problem while reading contacts with ContactsContract.Contacts.CONTENT_URI
I need to search a particular name from ma contacts... for that i gave the selection criteria like this
ContactsContract.Contacts.DISPLAY_NAME + " LIKE '"+constraint+"%'"
But for apostrophe(')... means ...when i gave apostrophe as constraint an (SQL error )exception is thrown.. for all other special characters , the search is working..
How can we handle constraint apostrophe(')... in search criteria.. boz we can have contact names havi开发者_如何学运维ng apostrophe in it (Eg: Jennifer'lo'pe_z)
How do I use a string literal that contains an embedded single-quote (') character?
The SQL standard specifies that single-quotes in strings are escaped by putting two single quotes in a row. SQL works like the Pascal programming language in the regard. SQLite follows this standard.
Example:
INSERT INTO xyz VALUES('5 O''clock');
SO, simply for your solution, use '' at the place of '. like
if(constraint.contains("'"))
constraint = constraint.replace("'", "''");
And then execute your query. This must help you.
Happy coding :)
精彩评论