1

I need to delete a specific row from table in my SQLite database.
This table contains paths to files.
And I need to delete paths, which contain specific extensions.
And I have troubles with this.
Nothing is deleted from my database.

For example my table name is ALL_PATHS and column name is PATH_NAME This is the way I am doing this.
I'll be very glad for any help thanks

private void deletePath(String extension){
    Database db = getWritableDatabase();
    String query = "DELETE FROM " + ALL_PATHS + " WHERE lower(" + PATH_NAME + ") LIKE '%" + extension + "'";
    Cursor cursor = db.rawQuery(query, null);
}
1
  • check your query using sqllite tools whether it is correct or not Commented Jan 20, 2016 at 10:33

2 Answers 2

5

The error is:

Cursor cursor = db.rawQuery(query, null);

While it should be

db.execSQL(query);

Because DELETE is a command, not a query (SELECT)

Sign up to request clarification or add additional context in comments.

2 Comments

I'm glad to know that!
@HrundiV.Bakshi Sir , Great
0

use Content values

String table = "beaconTable";
String whereClause = "_id" + "=?";
String[] whereArgs = new String[] { String.valueOf(row) };
db.delete(table, whereClause, whereArgs);

1 Comment

But in my case need to delete rows, which contain special extension in path. So i need to use LIKE keyword. And in your case we are checking, if they are equal.

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.