Raise NotSuppoertdError if tpc is used with PostgreSQL < 8.1

This commit is contained in:
Daniele Varrazzo 2010-10-13 00:28:42 +01:00
parent ab8e145063
commit 5dbeeba0f2
2 changed files with 14 additions and 0 deletions

View File

@ -147,6 +147,15 @@ HIDDEN PyObject *conn_tpc_recover(connectionObject *self);
"in asynchronous mode"); \
return NULL; }
#define EXC_IF_TPC_NOT_SUPPORTED(self) \
if ((self)->server_version < 80100) { \
PyErr_Format(NotSupportedError, \
"server version %d: " \
"two-phase transactions not supported", \
(self)->server_version); \
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); \

View File

@ -179,6 +179,7 @@ static PyObject *
psyco_conn_xid(connectionObject *self, PyObject *args, PyObject *kwargs)
{
EXC_IF_CONN_CLOSED(self);
EXC_IF_TPC_NOT_SUPPORTED(self);
return PyObject_Call((PyObject *)&XidType, args, kwargs);
}
@ -196,6 +197,7 @@ psyco_conn_tpc_begin(connectionObject *self, PyObject *args)
EXC_IF_CONN_CLOSED(self);
EXC_IF_CONN_ASYNC(self, tpc_begin);
EXC_IF_TPC_NOT_SUPPORTED(self);
if (!PyArg_ParseTuple(args, "O", &oxid)) {
goto exit;
@ -363,6 +365,7 @@ psyco_conn_tpc_commit(connectionObject *self, PyObject *args)
{
EXC_IF_CONN_CLOSED(self);
EXC_IF_CONN_ASYNC(self, tpc_commit);
EXC_IF_TPC_NOT_SUPPORTED(self);
return _psyco_conn_tpc_finish(self, args,
conn_commit, "COMMIT PREPARED");
@ -376,6 +379,7 @@ psyco_conn_tpc_rollback(connectionObject *self, PyObject *args)
{
EXC_IF_CONN_CLOSED(self);
EXC_IF_CONN_ASYNC(self, tpc_rollback);
EXC_IF_TPC_NOT_SUPPORTED(self);
return _psyco_conn_tpc_finish(self, args,
conn_rollback, "ROLLBACK PREPARED");
@ -390,6 +394,7 @@ psyco_conn_tpc_recover(connectionObject *self, PyObject *args)
EXC_IF_CONN_CLOSED(self);
EXC_IF_CONN_ASYNC(self, tpc_recover);
EXC_IF_TPC_PREPARED(self, tpc_recover);
EXC_IF_TPC_NOT_SUPPORTED(self);
if (!PyArg_ParseTuple(args, "")) { return NULL; }