Changeset 876 for trunk/pg.py


Ignore:
Timestamp:
Jul 14, 2016, 8:21:19 AM (3 years ago)
Author:
cito
Message:

Fixed issues when remote server version < 9.0

Though this is not officially supported and tested,
sometimes you just have to access those legacy databases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pg.py

    r872 r876  
    904904    def __missing__(self, typ):
    905905        """Create a cast function if it is not cached.
    906        
     906
    907907        Note that this class never raises a KeyError,
    908908        but returns None when no special cast function exists.
     
    10501050        simple: the simple PyGreSQL type name
    10511051        typtype: b = base type, c = composite type etc.
    1052         category: A = Array, b =Boolean, C = Composite etc.
     1052        category: A = Array, b = Boolean, C = Composite etc.
    10531053        delim: delimiter for array types
    10541054        relid: corresponding table for composite types
     
    10831083        self.query = db.query
    10841084        self.escape_string = db.escape_string
     1085        if db.server_version < 80400:
     1086            # older remote databases (not officially supported)
     1087            self._query_pg_type = (
     1088                "SELECT oid, typname, typname::text::regtype,"
     1089                " typtype, null as typcategory, typdelim, typrelid"
     1090                " FROM pg_type WHERE oid=%s::regtype")
     1091        else:
     1092            self._query_pg_type = (
     1093                "SELECT oid, typname, typname::regtype,"
     1094                " typtype, typcategory, typdelim, typrelid"
     1095                " FROM pg_type WHERE oid=%s::regtype")
    10851096
    10861097    def add(self, oid, pgtype, regtype,
     
    11051116        """Get the type info from the database if it is not cached."""
    11061117        try:
    1107             res = self.query("SELECT oid, typname, typname::regtype,"
    1108                 " typtype, typcategory, typdelim, typrelid"
    1109                 " FROM pg_type WHERE oid=%s::regtype" %
    1110                 (_quote_if_unqualified('$1', key),), (key,)).getresult()
     1118            q = self._query_pg_type % (_quote_if_unqualified('$1', key),)
     1119            res = self.query(q, (key,)).getresult()
    11111120        except ProgrammingError:
    11121121            res = None
     
    13801389        self.adapter = Adapter(self)
    13811390        self.dbtypes = DbTypes(self)
     1391        if db.server_version < 80400:
     1392            # support older remote data bases
     1393            self._query_attnames = (
     1394                "SELECT a.attname, t.oid, t.typname, t.typname::text::regtype,"
     1395                " t.typtype, null as typcategory, t.typdelim, t.typrelid"
     1396                " FROM pg_attribute a"
     1397                " JOIN pg_type t ON t.oid = a.atttypid"
     1398                " WHERE a.attrelid = %s::regclass AND %s"
     1399                " AND NOT a.attisdropped ORDER BY a.attnum")
     1400        else:
     1401            self._query_attnames = (
     1402                "SELECT a.attname, t.oid, t.typname, t.typname::regtype,"
     1403                " t.typtype, t.typcategory, t.typdelim, t.typrelid"
     1404                " FROM pg_attribute a"
     1405                " JOIN pg_type t ON t.oid = a.atttypid"
     1406                " WHERE a.attrelid = %s::regclass AND %s"
     1407                " AND NOT a.attisdropped ORDER BY a.attnum")
    13821408        db.set_cast_hook(self.dbtypes.typecast)
    13831409        self.debug = None  # For debugging scripts, this can be set
     
    18061832            if with_oid:
    18071833                q = "(%s OR a.attname = 'oid')" % q
    1808             q = ("SELECT a.attname, t.oid, t.typname, t.typname::regtype,"
    1809                 " t.typtype, t.typcategory, t.typdelim, t.typrelid"
    1810                 " FROM pg_attribute a"
    1811                 " JOIN pg_type t ON t.oid = a.atttypid"
    1812                 " WHERE a.attrelid = %s::regclass AND %s"
    1813                 " AND NOT a.attisdropped ORDER BY a.attnum") % (
    1814                     _quote_if_unqualified('$1', table), q)
     1834            q = self._query_attnames % (_quote_if_unqualified('$1', table), q)
    18151835            names = self.db.query(q, (table,)).getresult()
    18161836            types = self.dbtypes
Note: See TracChangeset for help on using the changeset viewer.