質問

I used the ContactsQuery to search for the contact name on the device. My code is quite similar to this sampleContactsActivity on github:

However, the application throws the SQLiteException when I enter number key on the contact search bar.

The Selection query I used was:

final static String SELECTION =
            (Helper.hasHoneycomb() ? Contacts.DISPLAY_NAME_PRIMARY : Contacts.DISPLAY_NAME) +
            "<>''" + " AND " + Contacts.IN_VISIBLE_GROUP + "=1";

When I enter number key '6', the error messages that shown in log are:

  android.database.sqlite.SQLiteException: near ":6": syntax error (code 1): , while compiling: SELECT _id, lookup, display_name, photo_thumb_uri, sort_key FROM view_contacts_restricted JOIN (SELECT contact_id AS snippet_contact_id FROM search_index WHERE search_index MATCH content:6*  OR name:1E* UNION  SELECT contact_id AS snippet_contact_id FROM phone_lookup JOIN raw_contacts ON ( raw_contacts._id=raw_contact_id) WHERE normalized_number LIKE '%6%') ON (_id=snippet_contact_id) WHERE ((display_name<>'' AND in_visible_group=1)) ORDER BY sort_key

This issue only happens to one of the Samsung Galaxy III devices.

役に立ちましたか?

解決 2

I resolved the problem by converting the number to string before formatting the SQL query search. I suspect that on that specific device, the contacts provider implementation doesn't automatically convert the number to string, and ends up with a SQL syntax error.

I also noticed that special character keys were problematic as well. So I simply add '' to all none-character inputs

他のヒント

This is a bug in the code that formats the SQL query, which is in the contacts provider implementation, which is part of that device's firmware.

Update the Android version on that device, if possible, or avoid number searches.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top