Patch to add get_backend_pid() method to connection

Casey Duncan <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
I've seen others request this and I needed it, so here's the patch. I  
included the method in the PSYCOPG_EXTENSIONS ifdef block.

The patch is against 2.0.7, but I've also applied it successfully  
against 2.0.6. Hopefully it will apply to the svn trunk, if not, let  
me know.

-Casey

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
connection_type.c.patch (application/octet-stream, 907 B)
--- connection_type.c.orig	2008-07-24 16:43:50.000000000 -0600
+++ connection_type.c	2008-07-24 16:54:51.000000000 -0600
@@ -230,6 +230,19 @@
     return PyInt_FromLong((long)PQtransactionStatus(self->pgconn));
 }
 
+/* get the current backend pid */
+
+#define psyco_conn_get_backend_pid_doc \
+"get_backend_pid() -- Get backend process id."
+
+static PyObject *
+psyco_conn_get_backend_pid(connectionObject *self)
+{
+    EXC_IF_CONN_CLOSED(self);
+
+    return PyInt_FromLong((long)PQbackendPID(self->pgconn));
+}
+
 #endif
 
 static PyObject *
@@ -262,6 +275,8 @@
      METH_VARARGS, psyco_conn_set_client_encoding_doc},
     {"get_transaction_status", (PyCFunction)psyco_conn_get_transaction_status,
      METH_VARARGS, psyco_conn_get_transaction_status_doc},
+    {"get_backend_pid", (PyCFunction)psyco_conn_get_backend_pid,
+     METH_NOARGS, psyco_conn_get_backend_pid_doc},
 #endif
     {NULL}
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.