0

我在这里有一个用于搜索联系人数据库的光标:

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);

但是如果编辑文本中john smith 的名称是并且联系人数据库中的名称是John Smith我没有得到任何结果。

如何使光标不检查是否区分大小写?

4

2 回答 2

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);
于 2013-08-03T09:16:39.633 回答
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;
}

像这样使用..你的条件。

于 2013-08-03T09:28:22.093 回答