diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-10-13 00:28:42 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-05 09:34:49 +0000 |
| commit | 5dbeeba0f2760eb2344a34f1b25c952bfb4adb32 (patch) | |
| tree | 4c5f0ade7653aef51181f57ea0778af7b91b4563 | |
| parent | ab8e1450633a76e8400cf65ca5f07ffba5fd7821 (diff) | |
| download | psycopg2-5dbeeba0f2760eb2344a34f1b25c952bfb4adb32.tar.gz | |
Raise NotSuppoertdError if tpc is used with PostgreSQL < 8.1
| -rw-r--r-- | psycopg/connection.h | 9 | ||||
| -rw-r--r-- | psycopg/connection_type.c | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/psycopg/connection.h b/psycopg/connection.h index 85e2d26..5d056c5 100644 --- a/psycopg/connection.h +++ b/psycopg/connection.h @@ -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); \ diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 48f2780..bc3aa87 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -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; } |
