From 5dab867db40d60677a9f3b9f6333253bbae69b48 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sun, 19 Apr 2009 16:42:06 +0200 Subject: [PATCH] Added get_parameter_status() implementation --- ChangeLog | 3 +++ psycopg/connection_type.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/ChangeLog b/ChangeLog index ff290335..79ef2bc4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2009-04-19 Federico Di Gregorio + * psycopg/connection_type.c: patch from Marko Kreen to implement + get_parameter_status(). + * psycopg/connection.*: exposed protocol_version and server_version attributes on the connection object. diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index 1310fb55..27924b45 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -231,6 +231,36 @@ psyco_conn_get_transaction_status(connectionObject *self, PyObject *args) return PyInt_FromLong((long)PQtransactionStatus(self->pgconn)); } +/* get_parameter_status method - Get server parameter status */ + +#define psyco_conn_get_parameter_status_doc \ +"get_parameter_status(parameter) -- Get backend parameter status.\n\n" \ +"Potential values for ``parameter``:\n" \ +" server_version, server_encoding, client_encoding, is_superuser,\n" \ +" session_authorization, DateStyle, TimeZone, integer_datetimes,\n" \ +" and standard_conforming_strings\n" \ +"If server did not report requested parameter, None is returned.\n\n" \ +"See libpq docs for PQparameterStatus() for further details." + +static PyObject * +psyco_conn_get_parameter_status(connectionObject *self, PyObject *args) +{ + const char *param = NULL; + const char *val = NULL; + + EXC_IF_CONN_CLOSED(self); + + if (!PyArg_ParseTuple(args, "s", ¶m)) return NULL; + + val = PQparameterStatus(self->pgconn, param); + if (!val) { + Py_INCREF(Py_None); + return Py_None; + } + return PyString_FromString(val); +} + + /* lobject method - allocate a new lobject */ #define psyco_conn_lobject_doc \ @@ -353,6 +383,8 @@ static struct PyMethodDef connectionObject_methods[] = { 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_parameter_status", (PyCFunction)psyco_conn_get_parameter_status, + METH_VARARGS, psyco_conn_get_parameter_status_doc}, {"get_backend_pid", (PyCFunction)psyco_conn_get_backend_pid, METH_NOARGS, psyco_conn_get_backend_pid_doc}, {"lobject", (PyCFunction)psyco_conn_lobject,