Skip to content

Transaction processing

Thoroughbred Basic offers the ability to perform transaction processing within a Thoroughbred Basic program.

Transaction processing includes the means to initiate transaction entries to a log file, which has the ability to reconstruct a data file from entries made. Transaction processing gives you the option to maintain a running log file ensuring that all or none of the database changes are made permanent until a COMMITment is made. A ROLLBACK to the point where transaction processing started is also permitted. This is useful in the event of an unexpected error. The entries in the log file are a journal of all transaction entries.

For more information on COMMIT, LOG CLOSE, LOG OPEN, ROLLBACK, and TRANSACTION BEGIN directives, please refer to the Thoroughbred Basic Reference Manual.

For example, you would open the log file:

00010 LOG CLOSE
00020 LOG OPEN “LOG”+FID(0), “REWIND”
00030 OPEN(2) “DIRECTFILE”
00040 TRANSACTION BEGIN

Begin your transactions with the option to rollback or commit:

00110 TRANSACTION BEGIN
00120 CH1=UNT; OPEN(CH1) “MSORTFILE”
00130 CH2=UNT; OPEN(CH2) “DIRECTFILE”
00140 CLEAR ERC;
K$ = KEY(CH1);
READ RECORD(CH1) A$;
WRITE RECORD (CH2,KEY=K$,ERC=99) A$;
REMOVE(CH1,KEY=K$,ERC=99);
IF ERC
ROLLBACK
ELSE
COMMIT
FI

From the Thoroughbred Basic Developer Guide, version 8.9.1. Open this page in the PDF