Skip to content

Commit

Permalink
Ecpg should support COMMIT PREPARED and ROLLBACK PREPARED.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael Meskes committed Mar 13, 2017
1 parent dd12bef commit 43c79c7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/interfaces/ecpg/ecpglib/misc.c
Expand Up @@ -213,9 +213,15 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
* If we got a transaction command but have no open transaction, we
* have to start one, unless we are in autocommit, where the
* developers have to take care themselves. However, if the command is
* a begin statement, we just execute it once.
* a begin statement, we just execute it once. And if the command is
* commit or rollback prepared, we don't execute it.
*/
if (PQtransactionStatus(con->connection) == PQTRANS_IDLE && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
if (PQtransactionStatus(con->connection) == PQTRANS_IDLE &&
!con->autocommit &&
strncmp(transaction, "begin", 5) != 0 &&
strncmp(transaction, "start", 5) != 0 &&
strncmp(transaction, "commit prepared", 15) != 0 &&
strncmp(transaction, "rollback prepared", 17) != 0)
{
res = PQexec(con->connection, "begin transaction");
if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
Expand Down

0 comments on commit 43c79c7

Please sign in to comment.