FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Transaction security with DBF
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Transaction security with DBF
Posted: Wed Aug 31, 2022 07:26 AM

Hello friends,

How can we achieve transaction security with DBF?
Are there already ready-made solutions or concepts here?
Maybe also a documentation.

Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Transaction security with DBF
Posted: Wed Aug 31, 2022 02:51 PM

Dear Otto,

The idea is quite simple:

you use a history.dbf where you save all the operations descriptions that you are going to do, before doing them and after doing them, to confirm that they were performed successfully.

If any of those operations fails, then you "undo" what you have done. That is traditionally known as a "rollback".

SQL engines provide such capability but using DBFs we have to do it ourselves, but as you see, it is quite easy :-)

In example: you save this in history.dbf
1. going to save the customer details
2. customer details properly saved
3. going to save the items of the invoice
4. invoice items properly saved
and so on...

if at step 5 (in example) there is an error or an unexpected mistake, then you undo what you did, going backwards from step 4

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 309
Joined: Wed Mar 28, 2018 04:38 PM
Re: Transaction security with DBF
Posted: Wed Aug 31, 2022 09:02 PM

If you allow me, the logic could be improved to avoid conflicts in multi-user environments. I would add a semaphore to prevent two users from performing a transaction at the same time. The semaphore can be a file on disk, a record in a dbf table, an open socket, or any other signal that a user is performing a transaction.

Enviado desde mi motorola edge 20 mediante Tapatalk

--------

¿ Y porque no ?

¿ And why not ?
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Transaction security with DBF
Posted: Wed Aug 31, 2022 09:50 PM

Dear Otto
Perhaps the integrity of transactions made using the harbor RDDLOG is easier. It should be implemented conveniently, obviously, checking if the RDDLOG is executed in the event that there has been an error in the transaction.

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Transaction security with DBF
Posted: Wed Aug 31, 2022 10:18 PM

Dear Antonio, Cristobal and Victor,
thank you for your help.
I will expand my database accesses to include these suggestions.
Best regards,
Otto

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Transaction security with DBF
Posted: Fri Sep 09, 2022 06:30 AM
Hello all,
does someone know if we have in HARBOUR something similar to this?
Best regards,
Otto



http://www.dbase.com/help/Xbase/IDH_XBA ... BACK__.htm

Show

ROLLBACK( )

Topic group Related topics

Cancels the transaction by undoing all logged changes.

Syntax

ROLLBACK([<database name expC>])

<database name expC>

The name of the database in which to rollback the transaction.

If you began the transaction with BEGINTRANS(<database name expC>), you must issue ROLLBACK(<database name expC>). If instead you issue ROLLBACK( ), dBASE Plus ignores the ROLLBACK( ) statement.

If you began the transaction with BEGINTRANS( ), <database name expC> is an optional ROLLBACK( ) argument. If you include it, it must refer to the same database as the SET DATABASE TO statement that preceded BEGINTRANS( ).

Description

A transaction works by logging all changes. If an error occurs while attempting one of the changes, or the changes need to be undone for some other reason, the transaction is canceled by calling ROLLBACK( ). Otherwise, COMMIT( ) is called to clear the transaction log, thereby indicating that all the changes in the transaction were committed and that the transaction as a whole was posted.

Since new rows have already been written to disk, rows that were added during the transaction are deleted. In the case of DBF tables, the rows are marked as deleted, but are not physically removed from the table. If you want to actually remove them, you can pack the table with PACK. Rows that were just edited are returned to their saved values.

All locks made during a transaction are maintained until the transaction is completed. This ensures that no one else can make any changes until the transaction is committed or abandoned.

For more information on transactions, see BEGINTRANS( ).

OODML

Call the rollback( ) method of the Database object.


Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Transaction security with DBF
Posted: Fri Sep 09, 2022 07:15 AM

Hola,

Lo mas parecido a rollback que conozco para archivos .dbf es trabajar con archivos temporales y luego al final hacer un commit
Es una tecnica que mejora mucho la integridad referencial para el caso que se produzca un corte.
En todo caso el rollback, hasta donde yo se no existe en todas las bb.dd. y tampoco deshace totalmente todo

Salu2


Hello,

The closest thing I know of to rollback for .dbf files is to work with temporary files and then commit at the end
It is a technique that greatly improves the referential apparatus in the event that a cut occurs.
In any case, the rollback, as far as I know, does not exist in all bb.dd. and it doesn't totally undo everything

Salu2

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Transaction security with DBF
Posted: Fri Sep 09, 2022 09:00 AM

Hi,
Thank you very much.
Do you have a simple example to start with?
Best regards,
Otto

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Transaction security with DBF
Posted: Sat Sep 10, 2022 04:36 AM

RDD Built-in ROLLBACK feature:

viewtopic.php?f=3t=42174

&

Regards



G. N. Rao.

Hyderabad, India
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Transaction security with DBF
Posted: Sat Sep 10, 2022 06:14 AM

Dear Mr. RAo,
Thank you so much for your help.
Best regards,
Otto

Continue the discussion