From: Mark Huang Date: Mon, 4 Dec 2006 19:10:47 +0000 (+0000) Subject: - Fix casting of unicode strings in arrays X-Git-Tag: pycurl-7_13_1~212 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=ea972bb9fb462b9c318f5e68959c10c3bd98ed17;p=plcapi.git - Fix casting of unicode strings in arrays From federico on psycopg mailing list: Il giorno mar, 28/11/2006 alle 15.33 -0500, Mark Huang ha scritto: >> I've noticed that Unicode strings in PostgreSQL arrays are not cast to >> Python unicode objects: You need to register UNICODEARRAY just as you registered UNICODE but, ouch!, it is not exported! I'll make it exported in next release, right now you can use one of the internals: psycopg2.extensions.register_type(psycopg2._psycopg.UNICODEARRAY) --- diff --git a/PLC/PostgreSQL.py b/PLC/PostgreSQL.py index 30e9c46..6286a1a 100644 --- a/PLC/PostgreSQL.py +++ b/PLC/PostgreSQL.py @@ -5,12 +5,14 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: PostgreSQL.py,v 1.9 2006/11/08 22:43:02 mlhuang Exp $ +# $Id: PostgreSQL.py,v 1.10 2006/11/09 19:34:04 mlhuang Exp $ # import psycopg2 import psycopg2.extensions psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) +# UNICODEARRAY not exported yet +psycopg2.extensions.register_type(psycopg2._psycopg.UNICODEARRAY) import pgdb from types import StringTypes, NoneType diff --git a/psycopg2/psycopg/typecast_builtins.c b/psycopg2/psycopg/typecast_builtins.c index 8532b1f..0fc109d 100644 --- a/psycopg2/psycopg/typecast_builtins.c +++ b/psycopg2/psycopg/typecast_builtins.c @@ -34,9 +34,7 @@ typecastObject_initlist typecast_builtins[] = { {"FLOAT", typecast_FLOAT_types, typecast_FLOAT_cast, NULL}, {"DECIMAL", typecast_DECIMAL_types, typecast_DECIMAL_cast, NULL}, {"UNICODE", typecast_UNICODE_types, typecast_UNICODE_cast, NULL}, - /* XXX Unicode array elements are always cast to regular Python strings */ - /* {"STRING", typecast_STRING_types, typecast_STRING_cast, NULL}, */ - {"STRING", typecast_STRING_types, typecast_UNICODE_cast, NULL}, + {"STRING", typecast_STRING_types, typecast_STRING_cast, NULL}, {"BOOLEAN", typecast_BOOLEAN_types, typecast_BOOLEAN_cast, NULL}, {"DATETIME", typecast_DATETIME_types, typecast_DATETIME_cast, NULL}, {"TIME", typecast_TIME_types, typecast_TIME_cast, NULL},