From: SourceForge.net <no...@so...> - 2004-10-21 14:23:50
|
Bugs item #1051520, was opened at 2004-10-21 14:23 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116528&aid=1051520&group_id=16528 Category: PgSQL Group: None Status: Open Resolution: None Priority: 5 Submitted By: Florquin Renaud (florquin) Assigned to: Nobody/Anonymous (nobody) Summary: __unicodeConvert doesn't support PgArray of Unicode Strings Initial Comment: If we have PgArray of Unicode Strings, PyPgSQL fails. E.g. c = db.cursor() query = "CREATE TABLE test (id TEXT, values TEXT[]); c.execute(query) query = "INSERT INTO test values (%s, %s);" values = [] values.append(1) values.append([u"abc", u"dé"]) c.execute(query, values) c.close() db.commit() File "D:\Soft\Python23\lib\site- packages\pyPgSQL\PgSQL.py", line 3054, in execute parms = _quoteall(parms[0]) File "D:\Soft\Python23\lib\site- packages\pyPgSQL\PgSQL.py", line 2286, in _quoteall t = tuple(map(_quote, vdict)) File "D:\Soft\Python23\lib\site- packages\pyPgSQL\PgSQL.py", line 2255, in _quote return value._quote() File "D:\Soft\Python23\lib\site- packages\pyPgSQL\PgSQL.py", line 1175, in _quote return _handleArray(self.value) File "D:\Soft\Python23\lib\site- packages\pyPgSQL\PgSQL.py", line 2238, in _handleArray _j = '%s%s,' % (_j, PgQuoteString(str(_i), 1)) UnicodeEncodeError: 'ascii' codec can't encode character u'\x82' in position 0: ordinal not in range(128) The cause is that the routine __unicodeConvert doesn't take into account PgArray of Unicode Strings If we modify the __unicodeConvert and add the two marked line then there is no more error: 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 isinstance(item, PgArray): # !!! converted_obj.append(PgArray(self.__unicodeConvert (item.value))) # !!! else: converted_obj.append(item) return converted_obj ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=116528&aid=1051520&group_id=16528 |