Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Row in SQLite in Android

People also ask

How do I delete a row in Android?

To delete rows from a table, you need to provide selection criteria that identify the rows to the delete() method. The mechanism works the same as the selection arguments to the query() method. It divides the selection specification into a selection clause(where clause) and selection arguments.

How do I delete a SQLite database?

SQLite Drop Database You just have to delete the file manually. Here filename is always unique i.e. database name is always unique and it is case-sensitive. SQLite stores the whole database in a single disk file so if you want to delete the database then manually go that file location and delete it.

How do you clear a table in SQLite?

sqlite> DELETE FROM table_name; Following is the basic syntax of DROP TABLE. sqlite> DROP TABLE table_name; If you are using DELETE TABLE command to delete all the records, it is recommended to use VACUUM command to clear unused space.


You can try like this:

 //---deletes a particular title---
public boolean deleteTitle(String name) 
{
    return db.delete(DATABASE_TABLE, KEY_NAME + "=" + name, null) > 0;
}

or

public boolean deleteTitle(String name) 
{
    return db.delete(DATABASE_TABLE, KEY_NAME + "=?", new String[]{name}) > 0;
}

Try like that may you get your solution

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

it's better to use whereargs too;

db.delete("tablename","id=? and name=?",new String[]{"1","jack"});

this is like useing this command:

delete from tablename where id='1' and name ='jack'

and using delete function in such way is good because it removes sql injections.


Till i understand your question,you want to put two conditions to select a row to be deleted.for that,you need to do:

public void deleteEntry(long row,String key_name) {

      db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row + " and " + KEY_NAME + "=" + key_name, null);

      /*if you just have key_name to select a row,you can ignore passing rowid(here-row) and use:

      db.delete(DATABASE_TABLE, KEY_NAME + "=" + key_name, null);
      */  

}

Try this code

public void deleteRow(String value)
{
SQLiteDatabase db = this.getWritableDatabase();       
db.execSQL("DELETE FROM " + TABLE_NAME+ " WHERE "+COlUMN_NAME+"='"+value+"'");
db.close();
}