mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
Fixed segfault in connection.set_client_encoding().
This commit is contained in:
parent
a6b4a8b092
commit
67720de497
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user