Message-ID: From: "markmaker (@markmaker)" To: "postgresql-interfaces/psqlodbc" Date: Wed, 21 May 2025 07:30:14 +0000 Subject: Re: [postgresql-interfaces/psqlodbc] issue #116: Understanding Transactions in ODBC In-Reply-To: References: List-Id: X-GitHub-Author-Login: markmaker X-GitHub-Comment-Id: 2896902434 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 116 X-GitHub-Repo: postgresql-interfaces/psqlodbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/postgresql-interfaces/psqlodbc/issues/116#issuecomment-2896902434 Content-Type: text/plain; charset=utf-8 Thanks @davecramer, > There is a way to see if you are in a transaction From outside the ODBC driver? How? > Also you are correct this is how you control transactions So to begin a transaction, I would 1. `SQLSetConnectAttr(... SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF ...);` 2. `SQLSetConnectAttr( ... SQL_ATTR_TXN_ISOLATION, SQL_TXN_SERIALIZABLE ...);` To commit I would... 1. `SQLEndTran(... SQL_COMMIT);` 2. `SQLSetConnectAttr(... SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_ON ...);` 3. `SQLSetConnectAttr( ... SQL_ATTR_TXN_ISOLATION, SQL_TXN_READ_COMMITTED ...);` Rollback the same but with `SQL_ROLLBACK` in the first call. ### Error handling If I can't commit (deadlock etc.) then it is _implicitly_ a rollback, right? Or should I then call `SQLEndTran(... SQL_ROLLBACK)` to be on the safe side? I any case, I would still continue with 2. and 3. _Mark