Olaf Doschke
Programmer
A big hello to anyone still using DBCs,
As may be well known I am not a big proponent of DBFs anymore, since SMB and oplocks make life harder for shared DBCs. But in recent threads, alternatives like NAS system seem very stable, as they are often based on Linux and may either not implement the SMBv3 protocol or are able to be configured in ways you get no file corruption of DBFs.
Well, no matter exactly how and why you'd also still use DBCs, one feature I was missing is transaction logs. I started this a few years ago but it also stalled for a long time and now I took the time to finish it to a usable level. You find a first version including the infrastructure to get started easily and incorporate this into your application DBCs.
VFPTransactions
More details in the repository. When you don't use Git the easiest way to get the project is to use the feature of downloading the repository as a single ZIP and then unzip anywhere you work with your VFP projects. sampleusage.prg will reveal anything you need to know to apply this to your own DBCs, but the project also comes with a little sampledatabase.dbc that will demonstrate how this works. The initial state of the sampledatabase.DBC also is kept as is in the sample usage and a copy is generated, modified, and then used.
Ideas about usage are manifold, for example, you might base a replication process on the transaction log data. And even as is, the log can also be seen as a data history or audit trail of your data. In fact, not only the data that makes it through being committed by END TRANSACTION or TABLEUPDATE flushing buffers, etc. As the log mainly is based on reacting to any insert/update/delete trigger, makes a copy record object and writes them out to log tables in a different session than the original DBF usage, this data can even be persisted when your main application calls ROLLBACK or TABLEUPDATE()s fail in your session for any reasons.
As said, much more is described on the Github repository. I think I propose this to become a VFPX project, as I see no project in VFPX about that topic of extending a DBC with a transaction log.
And last not least, this isn't just interesting when you are making extensive use of VFP transactions. In one way it extends their meaning and motivates transaction usage, on the other side it also will log what happens at transaction level 0 outside of any transaction, as it catches all data change events in the form of the insert/update/delete triggers that can be defined for DBC tables. So it's a very general logger of all DBF changes happening in DBFs belonging to a DBC.
In its current form, it can also be used to maybe debug what happens in your data access and business objects, as the logging is quite verbose about every little trigger caused. So it can also be a debugging tool. A little downside is, that both the codebase and the output data are quite overwhelming, if you expect a single output dbf or even text log, that's not how this works. AS said mainly the triggers are the entry point for the logging, and to keep this just a brief interruption from the application code the main trigger procedures do nothing more than mainly SCATTER NAME oRecord, creating a record object of the triggering table row and adding this enriched with further information to a queue, which then is processed by a timer for as long as items are in there. So after logs are written with a low lag time, the timer even disables itself and relies on triggers and queue to reactivate it, once new items get into the queue. Which makes it less resource hungry.
Bye, Olaf.
Olaf Doschke Software Engineering
As may be well known I am not a big proponent of DBFs anymore, since SMB and oplocks make life harder for shared DBCs. But in recent threads, alternatives like NAS system seem very stable, as they are often based on Linux and may either not implement the SMBv3 protocol or are able to be configured in ways you get no file corruption of DBFs.
Well, no matter exactly how and why you'd also still use DBCs, one feature I was missing is transaction logs. I started this a few years ago but it also stalled for a long time and now I took the time to finish it to a usable level. You find a first version including the infrastructure to get started easily and incorporate this into your application DBCs.
VFPTransactions
More details in the repository. When you don't use Git the easiest way to get the project is to use the feature of downloading the repository as a single ZIP and then unzip anywhere you work with your VFP projects. sampleusage.prg will reveal anything you need to know to apply this to your own DBCs, but the project also comes with a little sampledatabase.dbc that will demonstrate how this works. The initial state of the sampledatabase.DBC also is kept as is in the sample usage and a copy is generated, modified, and then used.
Ideas about usage are manifold, for example, you might base a replication process on the transaction log data. And even as is, the log can also be seen as a data history or audit trail of your data. In fact, not only the data that makes it through being committed by END TRANSACTION or TABLEUPDATE flushing buffers, etc. As the log mainly is based on reacting to any insert/update/delete trigger, makes a copy record object and writes them out to log tables in a different session than the original DBF usage, this data can even be persisted when your main application calls ROLLBACK or TABLEUPDATE()s fail in your session for any reasons.
As said, much more is described on the Github repository. I think I propose this to become a VFPX project, as I see no project in VFPX about that topic of extending a DBC with a transaction log.
And last not least, this isn't just interesting when you are making extensive use of VFP transactions. In one way it extends their meaning and motivates transaction usage, on the other side it also will log what happens at transaction level 0 outside of any transaction, as it catches all data change events in the form of the insert/update/delete triggers that can be defined for DBC tables. So it's a very general logger of all DBF changes happening in DBFs belonging to a DBC.
In its current form, it can also be used to maybe debug what happens in your data access and business objects, as the logging is quite verbose about every little trigger caused. So it can also be a debugging tool. A little downside is, that both the codebase and the output data are quite overwhelming, if you expect a single output dbf or even text log, that's not how this works. AS said mainly the triggers are the entry point for the logging, and to keep this just a brief interruption from the application code the main trigger procedures do nothing more than mainly SCATTER NAME oRecord, creating a record object of the triggering table row and adding this enriched with further information to a queue, which then is processed by a timer for as long as items are in there. So after logs are written with a low lag time, the timer even disables itself and relies on triggers and queue to reactivate it, once new items get into the queue. Which makes it less resource hungry.
Bye, Olaf.
Olaf Doschke Software Engineering