I am trying to execute an sql query Sugar.But I am getting exception. This is the query I am execting.
ArrayList<Folder> mFolderList = (ArrayList<Folder>) Folder.findWithQuery(Folder.class, "Select * from Folder where folderPath = " + mFileLists[i].getParent() + " and imagePath = " + mFileLists[i].getAbsolutePath());
Here the value for folderPath is the folder path of internal memory of device,eg: /storage/emulated/0/Download
But I am getting exception as
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
I couldn't find any error in this query.Can anyone please help me?
Your image path and folder path consists of "/" and sqlite query is not accepting it..
You can use DatabaseUtils to escape this...
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()));