How do I make a case insensitive query with ContentResolver in Android?

前端 未结 3 829
半阙折子戏
半阙折子戏 2021-02-08 04:45

My goal is to get all rows from native db with a specific email address on Android Gingerbread and above.

This query gets only the rows where the case also matches.

相关标签:
3条回答
  • 2021-02-08 05:32

    Please try (I suppose that mail is String object):

    Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            new String[] {Contacts._ID}, "lower("+ContactsContract.CommonDataKinds.Email.ADDRESS + ")=lower('"+ email +"')",
            null, null);
    

    or

    Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
            new String[] {Contacts._ID}, "lower("+ContactsContract.CommonDataKinds.Email.ADDRESS + ")=lower('"+ email +"')",
            new String[] {}, null);
    
    0 讨论(0)
  • 2021-02-08 05:33

    Also try

    Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                new String[] {Contacts._ID}, ContactsContract.CommonDataKinds.Email.ADDRESS + "=? COLLATE NOCASE",
                new String[] {email}, null);
    

    Note that added COLLATE NOCASE in the query.

    0 讨论(0)
  • 2021-02-08 05:35
    Cursor cursor = this.db.query("UserTbl", new String[] {"UserId",
                            "Username", "Password" },
                            "Username = ? COLLATE NOCASE AND Password = ? COLLATE NOCASE", new String[] { userNameString,
                                    passwordString }, null, null, null);
    
    0 讨论(0)
提交回复
热议问题