Encoding fixes.

This commit is contained in:
Federico Di Gregorio 2007-01-16 23:39:08 +00:00
parent f43a52f781
commit b074dd4d8b
3 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,9 @@
2007-01-16 Federico Di Gregorio <fog@initd.org>
* 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

View File

@ -101,9 +101,11 @@ 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);

View File

@ -24,6 +24,7 @@
#include <stringobject.h>
#include <string.h>
#include <ctype.h>
#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",