美文网首页
SQLite ormlite 相似查询时报错

SQLite ormlite 相似查询时报错

作者: 阿霖A00 | 来源:发表于2022-09-07 14:17 被阅读0次

使用ormlite框架进行like查询时,查询参数如果带有 ‘ 单引号,解析时将会报错。

java.sql.SQLException: Problems executing Android query: SELECT * FROM search_history WHERE keyword LIKE '%s'z%' ORDER BY updated DESC LIMIT 20

解决方案是将参数中的’单引号进行转义,转义成“双引号。

private fun filter(str: String): String {
    return str.replace("'", "''")
}

相关文章

网友评论

      本文标题:SQLite ormlite 相似查询时报错

      本文链接:https://www.haomeiwen.com/subject/wwsgnrtx.html