diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | psycopg/connection_int.c | 13 | ||||
-rw-r--r-- | psycopg/connection_type.c | 2 | ||||
-rw-r--r-- | sandbox/test.py | 5 |
4 files changed, 16 insertions, 7 deletions
@@ -1,5 +1,8 @@ 2005-10-01 Federico Di Gregorio <fog@debian.org> + * psycopg/connection_int.c: fixed segfault by moving PyErr_Format + after GIL acquisition (closes: #50). + * psycopg/connection_type.c: applied patch from Matt Goodall to fix some doc strings. diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 270ed6c..e99b8d3 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -239,13 +239,15 @@ conn_set_client_encoding(connectionObject *self, char *enc) pgres = PQexec(self->pgconn, query); if (pgres == NULL || PQresultStatus(pgres) != PGRES_COMMAND_OK ) { - PyErr_Format(OperationalError, "can't set encoding to '%s'", enc); res = -1; } - IFCLEARPGRES(pgres); + else { + /* no error, we can proceeed and store the new encoding */ + if (self->encoding) free(self->encoding); + self->encoding = strdup(enc); + } - if (self->encoding) free(self->encoding); - self->encoding = strdup(enc); + IFCLEARPGRES(pgres); } Dprintf("conn_set_client_encoding: set encoding to %s", self->encoding); @@ -253,5 +255,8 @@ conn_set_client_encoding(connectionObject *self, char *enc) pthread_mutex_unlock(&self->lock); Py_END_ALLOW_THREADS; + if (res == -1) + PyErr_Format(OperationalError, "can't set encoding to %s", enc); + return res; } diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index b05c668..e537a38 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -167,7 +167,7 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args) /* set_isolation_level method - switch connection isolation level */ #define psyco_conn_set_client_encoding_doc \ -"set_client_encoding(encoding) -> set client encoding 'encoding'" +"set_client_encoding(encoding) -> set client encoding to 'encoding'" static PyObject * psyco_conn_set_client_encoding(connectionObject *self, PyObject *args) diff --git a/sandbox/test.py b/sandbox/test.py index 96c8cec..17e96d0 100644 --- a/sandbox/test.py +++ b/sandbox/test.py @@ -1,12 +1,13 @@ import datetime import time -import psycopg +import psycopg2 #d = datetime.timedelta(12, 100, 9876) #print d.days, d.seconds, d.microseconds #print psycopg.adapt(d).getquoted() -conn = psycopg.connect("dbname=test") +conn = psycopg2.connect("dbname=test_unicode") +conn.set_client_encoding("xxx") curs = conn.cursor() #curs.execute("SELECT 1.0 AS foo") #print curs.fetchmany(2) |