diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-10-15 09:42:44 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-05 09:34:46 +0000 |
| commit | f435d15c956e5bc99d907af8f41f0985380ce591 (patch) | |
| tree | a90d5c84a1ef3de2828210913482472776236f28 /psycopg/connection_int.c | |
| parent | e651308287fa91b7f3f633a56ef0d02ad563c872 (diff) | |
| download | psycopg2-f435d15c956e5bc99d907af8f41f0985380ce591.tar.gz | |
Adding Notify object with payload.
Diffstat (limited to 'psycopg/connection_int.c')
| -rw-r--r-- | psycopg/connection_int.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index a69776f..8763c27 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -34,6 +34,7 @@ #include "psycopg/cursor.h" #include "psycopg/pqpath.h" #include "psycopg/green.h" +#include "psycopg/notify.h" /* conn_notice_callback - process notices */ @@ -133,21 +134,47 @@ conn_notice_clean(connectionObject *self) void conn_notifies_process(connectionObject *self) { - PGnotify *pgn; + PGnotify *pgn = NULL; + PyObject *notify = NULL; + PyObject *pid = NULL, *channel = NULL, *payload = NULL; + + /* TODO: we are called without the lock! */ while ((pgn = PQnotifies(self->pgconn)) != NULL) { - PyObject *notify; Dprintf("conn_notifies_process: got NOTIFY from pid %d, msg = %s", (int) pgn->be_pid, pgn->relname); - notify = PyTuple_New(2); - PyTuple_SET_ITEM(notify, 0, PyInt_FromLong((long)pgn->be_pid)); - PyTuple_SET_ITEM(notify, 1, PyString_FromString(pgn->relname)); - PyList_Append(self->notifies, notify); - Py_DECREF(notify); - PQfreemem(pgn); + if (!(pid = PyInt_FromLong((long)pgn->be_pid))) { goto error; } + if (!(channel = PyString_FromString(pgn->relname))) { goto error; } + if (!(payload = PyString_FromString(pgn->extra))) { goto error; } + + if (!(notify = PyObject_CallFunctionObjArgs((PyObject *)&NotifyType, + pid, channel, payload, NULL))) { + goto error; + } + + Py_DECREF(pid); pid = NULL; + Py_DECREF(channel); channel = NULL; + Py_DECREF(payload); payload = NULL; + + PyList_Append(self->notifies, (PyObject *)notify); + + Py_DECREF(notify); notify = NULL; + PQfreemem(pgn); pgn = NULL; } + return; /* no error */ + +error: + if (pgn) { PQfreemem(pgn); } + Py_XDECREF(notify); + Py_XDECREF(pid); + Py_XDECREF(channel); + Py_XDECREF(payload); + + /* TODO: callers currently don't expect an error from us */ + PyErr_Clear(); + } |
