diff --git a/ChangeLog b/ChangeLog index 89a5b07f..c0d3a52c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2007-01-16 Federico Di Gregorio + * psycopg/connection_type.c: .set_client_encoding() now converts the + argument to upper case to make sure it has the same case of the entries + in the PostgreSQL -> Python encoding conversion table. + * lib/extras.py: merged DictCursor from #143 and renamed it RealDictCursor because allows access by cursor keys _only_. Also cleaned up a little bit the implementation of both DictCursor and RealDictCursor by introducing diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c index 86da1052..90775dc4 100644 --- a/psycopg/adapter_qstring.c +++ b/psycopg/adapter_qstring.c @@ -100,10 +100,12 @@ qstring_quote(qstringObject *self) /* TODO: we need a real translation table from postgres encoding names to python ones here */ - + + Dprintf("qstring_quote: encoding to %s", self->encoding); + if (PyUnicode_Check(self->wrapped) && self->encoding) { PyObject *enc = PyDict_GetItemString(psycoEncodings, self->encoding); - /* note that pgenc is a borrowed reference */ + /* note that enc is a borrowed reference */ if (enc) { char *s = PyString_AsString(enc); diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index b55b325a..44eb1ad3 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -24,6 +24,7 @@ #include #include +#include #define PSYCOPG_MODULE #include "psycopg/config.h" @@ -179,12 +180,16 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args) static PyObject * psyco_conn_set_client_encoding(connectionObject *self, PyObject *args) { - char *enc = NULL; + char *pos, *enc = NULL; EXC_IF_CONN_CLOSED(self); if (!PyArg_ParseTuple(args, "s", &enc)) return NULL; - + + /* convert to upper case */ + for (pos = enc ; *pos != '\0' ; pos++) + *pos = toupper(*pos); + if (conn_set_client_encoding(self, enc) == 0) { Py_INCREF(Py_None); return Py_None; @@ -272,7 +277,6 @@ static struct PyMemberDef connectionObject_members[] = { static int connection_setup(connectionObject *self, char *dsn) { - int i; char *pos; Dprintf("connection_setup: init connection object at %p, refcnt = %d",