Welcome! Log In Create A New Profile

Advanced

[WB24] Begin - End Transaction

Posted by ericus 
[WB24] Begin - End Transaction
October 06, 2021 02:33PM
Good day

I know this is bad programming that I have not implemented this before but how do I do an HAdd/hModify of numerous files and then roll back those transactions if there is a problem with the update?

I now have problems where the first couple of records are created or modified and then there is an internet connection problem and that stuffs up my update because only some records were added or modified.

Hope this makes sense and thanks in advance for any suggestions.


Ericus Steyn
Re: [WB24] Begin - End Transaction
October 06, 2021 05:51PM
Hi

I'm not sure it works on webdev

[doc.pcsoft.fr]

[infosonline.net]



Edited 1 time(s). Last edit at 10/06/2021 05:53PM by infos.
Re: [WB24] Begin - End Transaction
October 06, 2021 06:36PM
Hi Ericus

By definition a db transaction execution needs to last for as little time as possible since it creates locks on the database. So in brief it is not a good practice to start a transaction at the beginning of a user process and wait until he/she finishes having three coffees in between...

In a modern (web) app, you cache up everything in one or more objects and only on submission of the whole you create the transaction block and do all updates/inserts in one process. (All modern apps have some sort of MVC pattern (Model-View-Controller) managing this and segregating concerns between UI, business logic and data layer. The model part will do the transaction in this case...)

Just my 2 cents

Peter Holemans
Re: [WB24] Begin - End Transaction
October 07, 2021 10:09AM
Hi Ericus,

HTransaction is your friend - in all WX products.
I would of course NOT choose to have any code (I mean inside the transaction) that depends on an internet connection, but it can be done !!
Just add this "internet-dependent code" inside an exception and return false and roll back the transaction if something unexpected goes wrong.

Regards
Steven Sitas
.
Re: [WB24] Begin - End Transaction
October 08, 2021 12:03PM
Thanks for the replies.

This is actually a batch of journals and the user captures them at their leisure. Every line captured is stored in a temporary table and when the user is finished he/she will click UPSDATE and all the transactions must be written to the database and various tables must be updated.

Normally there is no problem, even if it is a large batch, but with bad internet connection, this update of the various tables are interrupted.

With HTransactionStart and HTransactionEnd I can make sure that all the tables for one batch entry are updated correctly, if something goes wrong then the update is stopped but at least I know which rows were updated before and which rows must still be updated.

As you point out Silas at the time of updating I need to be sure the internet connection is ON. Sometimes it can be up to 10 tables that must be updated and I want to be sure al 10 are updated before proceeding with the next batch entry.

Silas do you have an example of that internet-dependent code?

Thanks in advance
Re: [WB24] Begin - End Transaction
October 08, 2021 12:12PM
Hi Ericus,

there is really nothing special about it, but here it goes:

Wrap everything in a procedure that returns TRUE at the end and FALSE anywhere YOU catch a problem.
Inside this procedure enable the "automatic management of errors and exceptions".
You will get something like this at the end of your procedure:

CASE ERROR:
CASE EXCEPTION:

- just return a FALSE inside the CASE:

CASE ERROR:
Result FALSE
CASE EXCEPTION:
Result FALSE

Now start your Transaction, call your procedure, and if it returns TRUE commit else rollback.

Regards
Steven Sitas
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: