【问题标题】:E/SQLiteLog: (1) near "ž": syntax error when filtering recycler using RoomE/SQLiteLog: (1) "ž" 附近:使用 Room 过滤回收器时出现语法错误
【发布时间】:2018-10-15 09:05:00
【问题描述】:

我在编写 sql 语法时遇到错误。我尝试通过用“常规”字符替换特殊字符来简单地使用 Room 过滤实体中某些字段的名称。这是原始查询:

    SimpleSQLiteQuery simple = new SimpleSQLiteQuery("SELECT * FROM station WHERE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(" + stationName + "), \"ž\", \"z\"), \"Ž\", \"z\"), \"č\", \"c\"), \"Č\", \"c\"), \"š\", \"s\"), \"Š\", \"s\"), \"ć\", \"c\"), \"Ć\", \"c\") LIKE " + "\" REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(stationName), \"ž\", \"z\"), \"Ž\", \"z\"), \"č\", \"c\"), \"Č\", \"c\"), \"š\", \"s\"), \"Š\", \"s\"), \"ć\", \"c\"), \"Ć\", \"c\")"+ "\" ORDER BY stationName ASC");

我收到错误:E/SQLiteLog: (1) 在“ž”附近:语法错误,我在 editText 中写入的字符无关紧要。我在这里遗漏了一些东西。感谢您的帮助!

【问题讨论】:

  • 我发现您的字符串连接存在问题。尝试构建表达式,从一个替换开始。仅在您知道它有效时才进行剪切和粘贴。
  • 尝试对这些字符串使用单引号...可能有效.. 例如:“'ž'”

标签: android sqlite android-room android-livedata


【解决方案1】:

我找到了解决办法:

    String sql = "SELECT * FROM station WHERE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(stationName), 'ž', 'z'), 'Ž', 'z'), 'č', 'c'), 'Č', 'c'), 'š', 's'), 'Š', 's'), 'ć', 'c'), 'Ć', 'c') LIKE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER('" + station + "'), 'ž', 'z'), 'Ž', 'z'), 'č', 'c'), 'Č', 'c'), 'š', 's'), 'Š', 's'), 'ć', 'c'), 'Ć', 'c') ORDER BY stationName ASC";

Amit Jangid 是正确的。我用单引号替换了所有内容!谢谢

【讨论】:

    猜你喜欢
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多