NOTIFY payload patch
"A.M." <agentm-/iWpWt6iY7eAP89PaY/[email protected]> Wed, 25 Aug 2010 15:39:01 -0400
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Here is a trivial patch to add support for NOTIFY payloads in 9.0b4:
(tg2env)[15:33:32][agentm@RD07:~/Dev/psycopg2]> git diff
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 902fdbb..7177e75 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -141,9 +141,10 @@ conn_notifies_process(connectionObject *self)
Dprintf("conn_notifies_process: got NOTIFY from pid %d, msg = %s",
(int) pgn->be_pid, pgn->relname);
- notify = PyTuple_New(2);
+ notify = PyTuple_New(3);
PyTuple_SET_ITEM(notify, 0, PyInt_FromLong((long)pgn->be_pid));
PyTuple_SET_ITEM(notify, 1, PyString_FromString(pgn->relname));
+ PyTuple_SET_ITEM(notify, 2, PyString_FromString(pgn->extra));
PyList_Append(self->notifies, notify);
Py_DECREF(notify);
PQfreemem(pgn);
Note that this will break code which unpacks the tuple in an assignment:
(pid,name) = dbconn.notifies.pop()
must become
(pid,name,payload) = dbconn.notifies.pop()
but as long as pop() doesn't return a Notification object, I don't see a way around this.
This patch was tested successfully against 8.4 and 9.0b4 libpq against a 9.0b4 server with an without payloads passed.
Cheers,
M