diff --git a/psycopg/connection.h b/psycopg/connection.h index a5553587..5b7c5d26 100644 --- a/psycopg/connection.h +++ b/psycopg/connection.h @@ -143,6 +143,11 @@ HIDDEN int conn_tpc_begin(connectionObject *self, XidObject *xid); "in asynchronous mode"); \ return NULL; } +#define EXC_IF_TPC_BEGIN(self, cmd) if ((self)->tpc_xid) { \ + PyErr_Format(ProgrammingError, "%s cannot be used " \ + "during a two-phase transaction", #cmd); \ + return NULL; } + #ifdef __cplusplus } #endif diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index d0e0c500..9cc32a2d 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -137,6 +137,7 @@ psyco_conn_commit(connectionObject *self, PyObject *args) { EXC_IF_CONN_CLOSED(self); EXC_IF_CONN_ASYNC(self, commit); + EXC_IF_TPC_BEGIN(self, commit); if (!PyArg_ParseTuple(args, "")) return NULL; @@ -158,6 +159,7 @@ psyco_conn_rollback(connectionObject *self, PyObject *args) { EXC_IF_CONN_CLOSED(self); EXC_IF_CONN_ASYNC(self, rollback); + EXC_IF_TPC_BEGIN(self, rollback); if (!PyArg_ParseTuple(args, "")) return NULL;