Changeset 840 for trunk/pgdb.py


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

Improve adaptation of hstore and empty array

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.