在 sugar 中执行 sql 查询时显示异常

Shows exception while executing sql query in sugar

我正在尝试执行 sql 查询 Sugar.But 我遇到异常。 这是我正在执行的查询。

ArrayList<Folder> mFolderList = (ArrayList<Folder>) Folder.findWithQuery(Folder.class, "Select * from Folder where folderPath = " + mFileLists[i].getParent() + " and imagePath = " + mFileLists[i].getAbsolutePath());

这里folderPath的值为设备内存的文件夹路径,例如:/storage/emulated/0/Download

但是我遇到了异常,因为

W/System.err: android.database.sqlite.SQLiteException: near "/": syntax error (code 1): , while compiling: Select * from Folder where folderPath =/storage/emulated/0/Download and imagePath = /storage/emulated/0/Download/.nomedia

我找不到任何错误 query.Can 谁能帮帮我?

您的图片路径和文件夹路径由“/”组成,sqlite 查询不接受它..

您可以使用 DatabaseUtils 来逃避这个...

ArrayList<Folder> mFolderList = (ArrayList<Folder>) Folder.findWithQuery(Folder.class, "Select * from Folder where folderPath = " + DatabaseUtils.sqlEscapeString(mFileLists[i].getParent()) + " and imagePath = " + DatabaseUtils.sqlEscapeString(mFileLists[i].getAbsolutePath()));