Sunday 7 April 2013

Use a string literal that contains an embedded single-quote (') character in Android


The SQL standard specifies that single-quotes in strings are escaped by putting two single quotes in a row. 
Example:
INSERT INTO xyz VALUES('5 O''clock');
So use '' at the place of '. like
if(constraint.contains("'")) 
            constraint = constraint.replace("'", "''");

ContactsContract.Contacts.DISPLAY_NAME + " LIKE '"+constraint+"%'"

No comments:

Post a Comment