我有这个光标在这里搜索联系人数据库:
String name_to_search = edittext.getText().toString();
String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" +name_to_search+ "\" )";
Cursor c = this.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
this.startManagingCursor(c);
但如果edittext中的名称为john smith
且联系人DB中的名称为John Smith
,则不会得到任何结果。
如何使光标不检查区分大小写?
答案 0 :(得分:0)
如果您的DBMS支持函数UPPER(),您可以执行以下操作:
String name_to_search = edittext.getText().toString().toUpperCase();
String select = "(UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") == \"" +name_to_search+ "\" )";
Cursor c = this.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
this.startManagingCursor(c);
答案 1 :(得分:0)
public String[] fetechRatio()//Search from database table WITH WHERE CONDITION
{
mDb= mHelper.getReadableDatabase();
String[] columns = new String[]{mHelper.COL_VALUE};
Cursor cursor=mDb.rawQuery("SELECT "+mHelper.COL_VALUE+" FROM " +mHelper.Table_Name + " WHERE " + mHelper.COL_HEAD + " = '" + alphbet + "' ORDER BY " + mHelper.COL_HEAD + " ", null);
String name[] =new String[cursor.getCount()];
cursor.moveToFirst();
value=cursor.getString(cursor.getColumnIndex(mHelper.COL_VALUE));
return name;
}
就这样使用..你的情况。