Changeset 847 for trunk/pgdb.py


Ignore:
Timestamp:
Feb 9, 2016, 5:51:46 AM (4 years ago)
Author:
cito
Message:

Fix issue with arrays and records containing unicode

Arrays and records with non-ascii unicode elements
did not work properly in Python 2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r846 r847  
    774774                return "'{}'"
    775775            q = self._quote
    776             return 'ARRAY[%s]' % ','.join(str(q(v)) for v in value)
     776            try:
     777                return 'ARRAY[%s]' % ','.join(str(q(v)) for v in value)
     778            except UnicodeEncodeError:  # Python 2 with non-ascii values
     779                return u'ARRAY[%s]' % ','.join(unicode(q(v)) for v in value)
    777780        if isinstance(value, tuple):
    778781            # Quote as a ROW constructor.  This is better than using a record
     
    782785            # when the records has a single column which is not really useful.
    783786            q = self._quote
    784             return '(%s)' % ','.join(str(q(v)) for v in value)
     787            try:
     788                return '(%s)' % ','.join(str(q(v)) for v in value)
     789            except UnicodeEncodeError:  # Python 2 with non-ascii values
     790                return u'(%s)' % ','.join(unicode(q(v)) for v in value)
    785791        try:
    786792            value = value.__pg_repr__()
Note: See TracChangeset for help on using the changeset viewer.