I have comment in listView "www.google.lv"
.
If I am trying to put again the same comment("www.google.lv"
), it should create this comment, but the same previous comment should be delete from database. They should not be duplicated, but is created as the lastest comment.
Is it possible?
how to createComment, but if the same exists, it delete the old one, in sqlite database?
Simply use the command INSERT OR REPLACE ...
.
Addition
Since you are using ContentValues to insert data into your database. Call database.insertWithOnConflict()
, instead of database.insert()
. Try:
database.insertWithOnConflict(MySQLiteHelper.TABLE_COMMENTS, null, values, SQLiteDatabase.CONFLICT_REPLACE);
(This assumes that you have an appropriate UNIQUE
constraint on your database...)