Added get_parameter_status() implementation

This commit is contained in:
Federico Di Gregorio 2009-04-19 16:42:06 +02:00
parent 39d6d8ad11
commit 5dab867db4
2 changed files with 35 additions and 0 deletions

View File

@ -1,5 +1,8 @@
2009-04-19 Federico Di Gregorio <fog@initd.org> 2009-04-19 Federico Di Gregorio <fog@initd.org>
* psycopg/connection_type.c: patch from Marko Kreen to implement
get_parameter_status().
* psycopg/connection.*: exposed protocol_version and * psycopg/connection.*: exposed protocol_version and
server_version attributes on the connection object. server_version attributes on the connection object.

View File

@ -231,6 +231,36 @@ psyco_conn_get_transaction_status(connectionObject *self, PyObject *args)
return PyInt_FromLong((long)PQtransactionStatus(self->pgconn)); 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", &param)) 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 */ /* lobject method - allocate a new lobject */
#define psyco_conn_lobject_doc \ #define psyco_conn_lobject_doc \
@ -353,6 +383,8 @@ static struct PyMethodDef connectionObject_methods[] = {
METH_VARARGS, psyco_conn_set_client_encoding_doc}, METH_VARARGS, psyco_conn_set_client_encoding_doc},
{"get_transaction_status", (PyCFunction)psyco_conn_get_transaction_status, {"get_transaction_status", (PyCFunction)psyco_conn_get_transaction_status,
METH_VARARGS, psyco_conn_get_transaction_status_doc}, 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, {"get_backend_pid", (PyCFunction)psyco_conn_get_backend_pid,
METH_NOARGS, psyco_conn_get_backend_pid_doc}, METH_NOARGS, psyco_conn_get_backend_pid_doc},
{"lobject", (PyCFunction)psyco_conn_lobject, {"lobject", (PyCFunction)psyco_conn_lobject,