From your link:
PostgreSQL actually treats every SQL statement as being executed within a transaction. If you do not issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it. A group of statements surrounded by BEGIN and COMMIT is sometimes called a transaction block.
Note: Some client libraries issue BEGIN and COMMIT commands automatically, so that you might get the effect of transaction blocks without asking. Check the documentation for the interface you are using.
Yes, that's correct. If this is the case as the note described the interface we discuss so far is sqldb and the OP stated that interfacing with PostgreSQL must not use the BEGIN/COMMIT automatically and need to be turned off as an option to avoid deadlocks. However, if it can be turned off as in zeosdb, but PostgreSQL treated every SQL statement as within in the realm of transaction anyway, so what's the point of improving sqldb to adapt to PG's requirements?
I still have to understand what tdbgrid was doing when it display data. I think as of this moment that whenever I see data on the grid(even if empty as long as it is connected to the datasource), it is in the context of open transaction. This is where the 'Transaction' we've been talking about differs. The single SQL statement that was treated by PG automatically with an implicit BEGIN/COMMIT block which will happen in an instant and the 'Transaction' that is open as long as the program is active, so if it is active, then deadlocks might occur in a multi-user environment. Imagine tens to hundreds of users using the same application with all of them are active(i.e., connected to the same DB and are all with active transactions). Single SQL statements with implicit BEGIN/COMMIT might be different in this context because it will happen so fast, than calling BEGIN/COMMIT explicitly with SQL statement like this: ' SELECT * FROM MyTable;' and the interface will wait for the user for the component.close/free commands before closing the transaction.
As I understood, the OP did not like this behavior, so if we follow the OP's requirements, we must not use tdbgrid at all but instead use TStringGrid to display data.
- Query for data and store them in the array using SQL by hand (postgres unit)
- Loop through the data in the array and store each of them in TStringGrid
A more laborious approach of fetching data.
Regards,
Allan