Hello everybody,
I'm trying to use Lazarus to develop a multiuser client application for a Postgresql database. I am a slightly somewhat experienced PG developer. So I am experimenting with the various approaches to connect to PG, one is SQLdb. Here I see an issue, which makes it IMO impossible to use SQLdb in a multiuser environment.
As I see, I have to connect to db via TPQConnection and then use TSQLTransaction together with TSQLQuery and TDataSource to query some rows of a table via SQL and show them in a Form. Even when I choose Action->caNone in the definition of the transaction, the query that is created and sent to Postgresql starts with "BEGIN;" (I see it in the log of PG). This transaction remains open, until I close the form, which started the query, then a "ROLLBACK;" is sent to the Database.
To understand, why this is an issue, one has to understand the way, PG handles transactions. Normally, you connect to PG at start of the application and then send a couple of queries to fill your form with the received data. None of them needs to be enclosed in "BEGIN;...ROLLBACK;" because transactions in PG are only used in one special case:
To combine a number of of queries (they can do all sort of CRUD), which are executed (COMMIT) or not (ROLLBACK) as an atomic(!) operation.
Therefor PG allows only one transaction at a time. And this should occur only for a period as short as possible.
But if one uses SQLdb to fill a form, this one possible transaction is opened and will not be closed until the end of the "living" of the form. As a programmer you are not able to use transactions in the normal way, PG needs it. And even worse: With an opened transaction for the whole time of living of the form one prevents other users to change the same data, which is queried by the form.
So for me SQLdb seems unusable with Postgresql in a multiuser env.
In short: The error is, that in TSQLTransaction the Action caNone has not the expected behavior to prevent "BEGIN;" and "ROLLBACK;".
Thank you.