getContentResolver().query android where clause

余生颓废 提交于 2021-01-28 05:28:01

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/14498958/getcontentresolver-query-android-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!