Connection encoding case fix (closes: #83).

This commit is contained in:
Federico Di Gregorio 2006-01-01 09:10:17 +00:00
parent e72f3dba40
commit 7db16edad3
7 changed files with 28 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2006-01-01 Federico Di Gregorio <fog@initd.org>
* psycopg/connection_int.c: PostgreSQL encoding names are now force
uppercase (after all PostgreSQL documentation reports them this way.)
2005-12-11 Federico Di Gregorio <fog@initd.org> 2005-12-11 Federico Di Gregorio <fog@initd.org>
* psycopg/typecast_array.c (typecast_array_cleanup): added functio * psycopg/typecast_array.c (typecast_array_cleanup): added functio

5
NEWS
View File

@ -3,6 +3,11 @@ What's new in psycopg 2.0 beta 7
* Ironed out last problems with times and date (should be quite solid now.) * Ironed out last problems with times and date (should be quite solid now.)
* Fixed problems with some arrays.
* Slightly better ZPsycopgDA (no more double connection objects in the menu
and other minor fixes.)
* Documentation! (With many kudos to piro.) * Documentation! (With many kudos to piro.)
What's new in psycopg 2.0 beta 6 What's new in psycopg 2.0 beta 6

View File

@ -53,7 +53,8 @@ conn_connect(connectionObject *self)
{ {
PGconn *pgconn; PGconn *pgconn;
PGresult *pgres; PGresult *pgres;
char *data; char *data, *tmp;
int i;
/* we need the initial date style to be ISO, for typecasters; if the user /* we need the initial date style to be ISO, for typecasters; if the user
later change it, she must know what she's doing... */ later change it, she must know what she's doing... */
@ -110,7 +111,17 @@ conn_connect(connectionObject *self)
IFCLEARPGRES(pgres); IFCLEARPGRES(pgres);
return -1; return -1;
} }
self->encoding = strdup(PQgetvalue(pgres, 0, 0)); tmp = PQgetvalue(pgres, 0, 0);
self->encoding = PyMem_Malloc(strlen(tmp));
if (self->encoding == NULL) {
/* exception already set by PyMem_Malloc() */
PQfinish(pgconn);
IFCLEARPGRES(pgres);
return -1;
}
for (i=0 ; i < strlen(tmp) ; i++)
self->encoding[i] = toupper(tmp[i]);
self->encoding[i] = '\0';
CLEARPGRES(pgres); CLEARPGRES(pgres);
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;

View File

@ -295,7 +295,7 @@ connection_dealloc(PyObject* obj)
if (self->closed == 0) conn_close(self); if (self->closed == 0) conn_close(self);
if (self->dsn) free(self->dsn); if (self->dsn) free(self->dsn);
if (self->encoding) free(self->encoding); if (self->encoding) PyMem_Free(self->encoding);
if (self->critical) free(self->critical); if (self->critical) free(self->critical);
Py_XDECREF(self->notice_list); Py_XDECREF(self->notice_list);

View File

@ -281,8 +281,9 @@ static encodingPair encodings[] = {
{"LATIN1", "latin_1"}, {"LATIN1", "latin_1"},
{"UNICODE", "utf_8"}, {"UNICODE", "utf_8"},
{"UTF8", "utf_8"}, {"UTF8", "utf_8"},
/* some compatibility stuff */ /* some compatibility stuff */
{"latin-1", "latin_1"}, {"LATIN-1", "latin_1"},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -1,5 +1,5 @@
[build_ext] [build_ext]
define=PSYCOPG_DEBUG,PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3 define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
# PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this) # PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this)
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower) # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.3 # HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.3

View File

@ -55,7 +55,7 @@ from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc from distutils.sysconfig import get_python_inc
from distutils.ccompiler import get_default_compiler from distutils.ccompiler import get_default_compiler
PSYCOPG_VERSION = '2.0b6' PSYCOPG_VERSION = '2.0b7'
version_flags = [] version_flags = []
# to work around older distutil limitations # to work around older distutil limitations