Changeset 787 for trunk/pgdb.py


Ignore:
Timestamp:
Jan 26, 2016, 1:59:18 PM (3 years ago)
Author:
cito
Message:

Make the type cache of pgdb available to users

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r786 r787  
    164164    """Cache for database types.
    165165
    166     This cache maps type OIDs to TypeInfo tuples containing the name
    167     and other important info for the database type with the given OID.
     166    This cache maps type OIDs and names to TypeInfo tuples containing
     167    important information on the associated database type.
    168168    """
    169169
     
    183183            q += "typname = '%s'" % self._escape_string(key)
    184184        self._src.execute(q)
    185         res = list(self._src.fetch(1)[0])
     185        res = self._src.fetch(1)
     186        if not res:
     187            raise KeyError('Type %s could not be found' % key)
     188        res = list(res[0])
    186189        res[0] = int(res[0])
    187190        res[2] = int(res[2])
     
    232235        self.connection = self._dbcnx = dbcnx
    233236        self._cnx = dbcnx._cnx
    234         self._type_cache = dbcnx._type_cache
     237        self.type_cache = dbcnx.type_cache
    235238        self._src = self._cnx.source()
    236239        # the official attribute for describing the result columns
     
    329332        """Make the description tuple for the given field info."""
    330333        name, typ, size, mod = info[1:]
    331         type_info = self._type_cache[typ]
     334        type_info = self.type_cache[typ]
    332335        type_code = type_info.name
    333336        if mod > 0:
     
    466469        except Error as err:
    467470            raise _db_error(str(err))
    468         typecast = self._type_cache.typecast
     471        typecast = self.type_cache.typecast
    469472        return [self.row_factory([typecast(typ, value)
    470473            for typ, value in zip(self.coltypes, row)]) for row in result]
     
    816819        self._cnx = cnx  # connection
    817820        self._tnx = False  # transaction state
    818         self._type_cache = TypeCache(cnx)
     821        self.type_cache = TypeCache(cnx)
    819822        self.cursor_type = Cursor
    820823        try:
Note: See TracChangeset for help on using the changeset viewer.