E / SQLiteLog:“ 1”附近的(1):使用Room过滤回收站时语法错误

时间:2018-10-15 09:05:01

标签: android sqlite android-room android-livedata

我在编写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中写什么字符都没有关系。我在这里错过了一些东西。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我找到了解决方法:

    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是正确的。我用单引号替换了所有!谢谢