summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2007-01-16 23:39:08 +0000
committerFederico Di Gregorio <fog@initd.org>2007-01-16 23:39:08 +0000
commitb074dd4d8b72c495e9896faa907f34f6a0595da1 (patch)
tree6a00978ae8701f4f0d024f9762888348c858cc50
parentf43a52f781cd34dd6e41ce04d4798550f81127d5 (diff)
downloadpsycopg2-b074dd4d8b72c495e9896faa907f34f6a0595da1.tar.gz
Encoding fixes.
-rw-r--r--ChangeLog4
-rw-r--r--psycopg/adapter_qstring.c6
-rw-r--r--psycopg/connection_type.c10
3 files changed, 15 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 89a5b07..c0d3a52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 86da105..90775dc 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 b55b325..44eb1ad 100644
--- a/psycopg/connection_type.c
+++ b/psycopg/connection_type.c
@@ -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",