SQLite Android Delete database row

carolewhite

New Member
I want to delete a row in the sqlite data base. Please refer to the sql datastructure and my current delete method which is not working. \[code\] private static final String[] TABLE_MESSAGE_FIELDS = { FIELD_USERNAME, "CHAR(32) NOT NULL", FIELD_READED, "INTEGER(1) NOT NULL", FIELD_SEND, "INTEGER(1) NOT NULL", FIELD_TIMESTAMP, "INTEGER(64) NOT NULL", FIELD_CONTENT, "TEXT NOT NULL", }; //more tables private static final String[] TABLE_MESSAGE_INDEXS = { FIELD_USERNAME, FIELD_READED, };\[/code\]This is the structure, basically it is an instant messenger (IM) android app, so the user can send and receive message. While the operations like receiving message etc are working, the option to delete is not.I am looking to delete the whole conversation between a user, in other words not the individual message in a conversation, but the whole conversation itself. I guess the right way is to find out the user name, and delete the entire row. The table TABLE_MESSAGE_FIELDS is contains the 5 columns indicating the message, I want to delete that entire conversation.This is how I go about it \[code\]public boolean deleteMessage(String userName){ SQLiteDatabase database = mLocalDatabase.getWritableDatabase(); final String[] COLUMNS = { FIELD_TIMESTAMP, FIELD_CONTENT }; final String SELECTION = FIELD_USERNAME + "=?" ; //database.beginTransaction();//do i need this? boolean result= database.delete(TABLE_MESSAGE,SELECTION,new String[]{userName})>=0; //database.endTransaction();//?? database.close(); return result; }\[/code\]
 
Top