AndrewMozley
Programmer
I am trying to establish a systematic and secure way of performing a bulk update of a database with a set of similar transactions.
Each transaction consists of updating 7 or 8 tables - most of these updates consist of replacing a few fields in one or more records of each table; in some tables I may be required to add records.
In the past I have been content to just lock each record and (if successful) update it. I recognise that this is not the best approach, partly because other applications may want to update the same tables (unlikely), and partly because I may fail to update a table (perhaps I do not find a record which I expect to exist). In this last case I wish to abandon the transaction with an error message, and undo any table updates.
I am not sure whether I should use record buffering, and tableupdate() / tablerevert(), or whether I should use BEGIN TRANSACTION / END TRANSACTION and perhaps ROLLBACK. – or indeed a combination of both approaches.
The general structure of the processing of one transaction (there is no user interaction) is to call a series of methods to update each table, and (if all goes well) to commit the whole set of updates.
Open_my_tables()
Ans1 = Update_table1()
Ans2 = Update_table2()
. . .
Ans8 = Update_table8()
. . .
IF Ans1 .AND. Ans2 .AND Ans3 . . .
* commit the transaction
ELSE
* reverse all updates
ENDIF
I have looked at several VFP manuals but am still unsure. I would very much appreciate guidance. Thank you
Each transaction consists of updating 7 or 8 tables - most of these updates consist of replacing a few fields in one or more records of each table; in some tables I may be required to add records.
In the past I have been content to just lock each record and (if successful) update it. I recognise that this is not the best approach, partly because other applications may want to update the same tables (unlikely), and partly because I may fail to update a table (perhaps I do not find a record which I expect to exist). In this last case I wish to abandon the transaction with an error message, and undo any table updates.
I am not sure whether I should use record buffering, and tableupdate() / tablerevert(), or whether I should use BEGIN TRANSACTION / END TRANSACTION and perhaps ROLLBACK. – or indeed a combination of both approaches.
The general structure of the processing of one transaction (there is no user interaction) is to call a series of methods to update each table, and (if all goes well) to commit the whole set of updates.
Open_my_tables()
Ans1 = Update_table1()
Ans2 = Update_table2()
. . .
Ans8 = Update_table8()
. . .
IF Ans1 .AND. Ans2 .AND Ans3 . . .
* commit the transaction
ELSE
* reverse all updates
ENDIF
I have looked at several VFP manuals but am still unsure. I would very much appreciate guidance. Thank you