mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-14 04:56:33 +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>
|
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
|
* psycopg/connection_type.c: applied patch from Matt Goodall to
|
||||||
fix some doc strings.
|
fix some doc strings.
|
||||||
|
|
||||||
|
|
|
@ -239,19 +239,24 @@ conn_set_client_encoding(connectionObject *self, char *enc)
|
||||||
pgres = PQexec(self->pgconn, query);
|
pgres = PQexec(self->pgconn, query);
|
||||||
|
|
||||||
if (pgres == NULL || PQresultStatus(pgres) != PGRES_COMMAND_OK ) {
|
if (pgres == NULL || PQresultStatus(pgres) != PGRES_COMMAND_OK ) {
|
||||||
PyErr_Format(OperationalError, "can't set encoding to '%s'", enc);
|
|
||||||
res = -1;
|
res = -1;
|
||||||
}
|
}
|
||||||
IFCLEARPGRES(pgres);
|
else {
|
||||||
|
/* no error, we can proceeed and store the new encoding */
|
||||||
if (self->encoding) free(self->encoding);
|
if (self->encoding) free(self->encoding);
|
||||||
self->encoding = strdup(enc);
|
self->encoding = strdup(enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IFCLEARPGRES(pgres);
|
||||||
|
}
|
||||||
|
|
||||||
Dprintf("conn_set_client_encoding: set encoding to %s", self->encoding);
|
Dprintf("conn_set_client_encoding: set encoding to %s", self->encoding);
|
||||||
|
|
||||||
pthread_mutex_unlock(&self->lock);
|
pthread_mutex_unlock(&self->lock);
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
|
if (res == -1)
|
||||||
|
PyErr_Format(OperationalError, "can't set encoding to %s", enc);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args)
|
||||||
/* set_isolation_level method - switch connection isolation level */
|
/* set_isolation_level method - switch connection isolation level */
|
||||||
|
|
||||||
#define psyco_conn_set_client_encoding_doc \
|
#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 *
|
static PyObject *
|
||||||
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import psycopg
|
import psycopg2
|
||||||
|
|
||||||
#d = datetime.timedelta(12, 100, 9876)
|
#d = datetime.timedelta(12, 100, 9876)
|
||||||
#print d.days, d.seconds, d.microseconds
|
#print d.days, d.seconds, d.microseconds
|
||||||
#print psycopg.adapt(d).getquoted()
|
#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 = conn.cursor()
|
||||||
#curs.execute("SELECT 1.0 AS foo")
|
#curs.execute("SELECT 1.0 AS foo")
|
||||||
#print curs.fetchmany(2)
|
#print curs.fetchmany(2)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user