array unicode decode
"Mignon, Laurent" <[email protected]> Wed, 14 Apr 2004 10:22:57 +0200
| Newsgroups | gmane.comp.python.db.pypgsql.user |
|---|---|
| Message-ID | <[email protected]> |
Hy,
When i passed to execute function a list with item(s) of arrray type as
parameter, array conent is not well unicode converted.
To solve this problem I have added the following lines to the
__unicodeConvert function
def __unicodeConvert(self, obj):
if type(obj) is StringType:
return obj
elif type(obj) is UnicodeType:
return obj.encode(*self.conn.client_encoding)
elif type(obj) in (ListType, TupleType):
converted_obj = []
for item in obj:
if type(item) is UnicodeType:
converted_obj.append(item.encode(*self.conn.client_encoding))
elif type(item) in (ListType,TupleType):
converted_obj.append( self.__unicodeConvert(item))
else:
converted_obj.append(item)
return converted_obj
elif type(obj) is DictType:
converted_obj = {}
for k, v in obj.items():
if type(v) is UnicodeType:
converted_obj[k] = v.encode(*self.conn.client_encoding)
else:
converted_obj[k] = v
return converted_obj
elif isinstance(obj, PgResultSet):
obj = copy.copy(obj)
for k, v in obj.items():
if type(v) is UnicodeType:
obj[k] = v.encode(*self.conn.client_encoding)
return obj
else:
return obj
Is it the good approach?
An other question, Why must I specify formally the keyword Array in the
query for the field of the array type.
"Insert into my_table (val1, array1) values (%s ARRAY%s)
thanks
Laurent Mignon
Software Engineer
Software AG Belgium
http://www.software-ag.com
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click