我想知道如何使用具有属性where
子句的查询方法。like
基本上我想要的是选择所有列 WHERE C_NAME 列是 LIKE 关键字。
我试过这个,但它不起作用:
cursor = db.query(TABLE, null, C_NAME, new String[] {"like '"+keyWord+"'"}, null, null, null);
我想知道如何使用具有属性where
子句的查询方法。like
基本上我想要的是选择所有列 WHERE C_NAME 列是 LIKE 关键字。
我试过这个,但它不起作用:
cursor = db.query(TABLE, null, C_NAME, new String[] {"like '"+keyWord+"'"}, null, null, null);
查看文档。他们说:
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.
所以试试这个:
cursor = db.query(TABLE, C_NAME, new String[] {C_NAME + " like '" + keyWord + "'"}, null, null, null);
另请参阅此答案以查看有关如何使用selectionArgs
(上面的第 4 个参数)的一些示例。那是keyWord
必须去的地方。
这个查询非常适合我
光标 cursor = db.query(true, TABLE_NAME, new String[]{ COLUMNS }, ROW + " LIKE ?", new > String[] { "%" + name + "%" }, null, null, null, null );