无法使用 sugar db 执行类似的查询

Unable to perform like queries with sugar db

我正在使用以下代码使用 Sugar Db 从 sqlite 获取数据

  String query = "SELECT * FROM trending where  like ( '%' ||" + existence + "|| '%' , category)";
    List<Trending> trendings = Trending.findWithQuery(Trending.class, query);

但是会产生以下错误,

 no such column: Existence (code 1): , while compiling: SELECT * FROM trending where  like ( '%' ||Existence|| '%' , category)

如何使用 Sugar Db 执行 LIKE 查询

与糖DB无关。你的成绩很差 SQL。查询应该是

... WHERE foo LIKE '%Existence%'

您缺少 foo 字段名称,并且由于您正在构建一个文本字符串来插入您的实际查询值,因此您也不需要 SQL 连接。

尝试:

query = "SELECT * FROM trending where category like '%" + existence + "%'"