I have an object that has three methods:
load()
: Loads database table's contents into a local object-attribute-listadd()
: adds an element to the listremove()
: removes an element from the listsave()
: Synchronizes the list with the database (this is where my question lies, details follow)
The first three methods are straight forward. But to synchronize the data back to the database-table, I want
- those elements that have changed to be
UPDATE
d/REPLACE
d - those that are new in the list and don't exist in the db table to be
INSERT
ed - those that are removed from the list but still exist in the db-table to be
DELETE
d
Is there a way to do all that magic in one incredibly-elegant SQL command or would I need to do it in two steps, such as
INSERT OR REPLACE...
first, thenDELETE FROM ... WHERE ...
?
Any ideas or suggestions would be much appreciated. Please excuse me if there is an obvious solution to this that I have missed.