Skip to content

Commit 43c79c7

Browse files
author
Michael Meskes
committed
Ecpg should support COMMIT PREPARED and ROLLBACK PREPARED.
The problem was that "begin transaction" was issued automatically before executing COMMIT/ROLLBACK PREPARED if not in auto commit. This fix by Masahiko Sawada fixes this.
1 parent dd12bef commit 43c79c7

File tree

1 file changed

+8
-2
lines changed
  • src/interfaces/ecpg/ecpglib

1 file changed

+8
-2
lines changed

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,15 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
213213
* If we got a transaction command but have no open transaction, we
214214
* have to start one, unless we are in autocommit, where the
215215
* developers have to take care themselves. However, if the command is
216-
* a begin statement, we just execute it once.
216+
* a begin statement, we just execute it once. And if the command is
217+
* commit or rollback prepared, we don't execute it.
217218
*/
218-
if (PQtransactionStatus(con->connection) == PQTRANS_IDLE && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
219+
if (PQtransactionStatus(con->connection) == PQTRANS_IDLE &&
220+
!con->autocommit &&
221+
strncmp(transaction, "begin", 5) != 0 &&
222+
strncmp(transaction, "start", 5) != 0 &&
223+
strncmp(transaction, "commit prepared", 15) != 0 &&
224+
strncmp(transaction, "rollback prepared", 17) != 0)
219225
{
220226
res = PQexec(con->connection, "begin transaction");
221227
if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))

0 commit comments

Comments
 (0)