From: Mignon, L. <Mi...@PC...> - 2004-04-14 08:27:20
|
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 |