0

In my database Inbox table have column name path to keep path of files but when i am trying to delete that record on the base of path the FATAL exception is thrown by Emulator.

// Deleting single File
public void deleteFile(File file) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_INBOX, KEY_PATH + " = "+file.getPath(),null);
    db.close();
}

Exception is :

FATAL EXCEPTION:main

android.database.sqlite.SQLiteExceprion: unrecognized token:"1kbFile"(code 1):,while compiling :DELETE inbox WHERE path=1kbFile.txt.

1kbFile.txt is path that i want to delete which is already saved in db. how can i solve this?

3
  • the sql needs to receive: path='1kbFile.txt' Commented Sep 8, 2013 at 19:51
  • so add some +"'"+ s Commented Sep 8, 2013 at 19:51
  • i.e.: KEY_PATH + " = '"+file.getPath() + "'" if it works I'll make it an official answer Commented Sep 8, 2013 at 19:52

2 Answers 2

1

Try to add ' to your file name, like this :

db.delete(TABLE_INBOX, KEY_PATH + " = '" + file.getPath() + "'", null);

Or you could also try to use separate parameters :

String whereString = KEY_PATH + " = ?";
String[] whereArgs = new String[] {file.getPath()};
db.delete(TABLE_INBOX, whereString, whereArgs);
Sign up to request clarification or add additional context in comments.

1 Comment

So @user2322360, did that finally help you solve your problem ?
0

Use ' around the values. E.g.:

db.delete(TABLE_INBOX, KEY_PATH + " = '"+file.getPath()+"'",null);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.