Dipin.K.G Dipin.K.G - 1 year ago 87
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 Source

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

mydb.delete(TABLE, "nickname = "+ DatabaseUtils.sqlEscapeString(name), null);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download