Search code examples
androidsqlitecursor

getContentResolver().query android where clause


My query is regarding the creation of the function parameters for getting data from the database.

I want the cursor to returns only specific rows instead of complete recordset.

c= getContentResolver().query(uri, null, "column1=? \"mysearch\" or column2=? "\mysearch"\", null, "date DESC");

I want to get the results where column1 like "mysearch" or column2 like "mysearch".

In the above example i have tried with some hardcoded values.

Regards,

Nirav


Solution

  • Got it after some workaround.

    The correct query will be

    String searchQuery = "column1 like '%" + searchKey
                    + "%' or column2 like '%" + searchKey + "%'";
    
    
            c = getContentResolver().query(uri, null, searchQuery, null,
                    "date DESC");
    

    Thanks,

    Nirav