Dipin.K.G Dipin.K.G - 29 days ago 9
Android Question

How to delete row in database with no ids

I have an idless database in my application. How can I delete any of the rows? My database code is as follows:

mydb=Nickname.this.openOrCreateDatabase("private", 0, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS numbers(nickname varchar,number INT(13))");


Anyone know how it is possible?

mydb=Clear.this.openOrCreateDatabase("private", 0, null);
mydb.execSQL("CREATE TABLE IF NOT EXISTS numbers(_id INTEGER PRIMARY KEY,nickname varchar,number INT(13))");
mydb.execSQL("DELETE FROM numbers WHERE id='=?' AND number='"+num+"'");

//num is string which contains which number i wish to delete

Answer

The SQLDatabase object has a delete method. public int delete (String table, String whereClause, String[] whereArgs)

mydb.delete(TABLE, "nickname = "+ DatabaseUtils.sqlEscapeString(name), null);