0

ALL, I have a DB with some data. I also have a C++ application that communicates with the DB.

Which scenario is more efficient?

Scenario 1:

  1. User hit "Edit Data" button.
  2. Program reads data from DB and presents it for editing
  3. User edit the data and hit "Save" button
  4. Program creates new object with the newly saved data then makes the comparison with the old object.
  5. Program issues some UPDATE statements.

Scenario 2:

  1. Steps 1-3 are the same.
  2. Program overwrites an old object data with the new data.
  3. Program issue DELETE/INSERT statements in one transaction.

I'm inclined to say scenario 2.

4

1 回答 1

1

Its a question of which is efficient and transactionally sound. Deleting an existing object to perform an update is not transactionally sound. Updates exist to update existing entities in the database. If you are using synthetic keys you cant use this approach at all.

In most system, a refetch (to at least check if the object your about to commit has been modified since you requested it from the database) is mandatory.

Step 4 should read, refetch the object from the database to ensure it hasnt changed, then commit update or rollback.

于 2012-10-28T05:55:37.130 回答