Changeset 840 for trunk


Ignore:
Timestamp:
Feb 8, 2016, 12:32:50 PM (4 years ago)
Author:
cito
Message:

Improve adaptation of hstore and empty array

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r839 r840  
    769769            # you need to add an explicit typecast when passing empty arrays.
    770770            # The ARRAY keyword is actually only necessary at the top level.
     771            if not value:  # exception for empty array
     772                return "'{}'"
    771773            q = self._quote
    772774            return 'ARRAY[%s]' % ','.join(str(q(v)) for v in value)
     
    15861588
    15871589    _re_quote = regex('^[Nn][Uu][Ll][Ll]$|[ ,=>]')
     1590    _re_escape = regex(r'(["\\])')
    15881591
    15891592    @classmethod
     
    15931596        if not s:
    15941597            return '""'
    1595         s = s.replace('"', '\\"')
    1596         if cls._re_quote.search(s):
     1598        quote = cls._re_quote.search(s)
     1599        s = cls._re_escape.sub(r'\\\1', s)
     1600        if quote:
    15971601            s = '"%s"' % s
    15981602        return s
  • trunk/tests/test_dbapi20.py

    r839 r840  
    628628        finally:
    629629            con.close()
    630         d = {'k': 'v', 'foo': 'bar', 'baz': 'whatever',
     630        d = {'k': 'v', 'foo': 'bar', 'baz': 'whatever', 'back\\': '\\slash',
    631631            '1a': 'anything at all', '2=b': 'value = 2', '3>c': 'value > 3',
    632632            '4"c': 'value " 4', "5'c": "value ' 5", 'hello, world': '"hi!"',
Note: See TracChangeset for help on using the changeset viewer.