0

I have an object that has three methods:

  • load(): Loads database table's contents into a local object-attribute-list
  • add(): adds an element to the list
  • remove(): removes an element from the list
  • save(): 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 UPDATEd/REPLACEd
  • those that are new in the list and don't exist in the db table to be INSERTed
  • those that are removed from the list but still exist in the db-table to be DELETEd

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, then
  • DELETE 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.

4

0 回答 0