Changeset 704


Ignore:
Timestamp:
Jan 9, 2016, 9:48:47 AM (4 years ago)
Author:
cito
Message:

Simplify code by removing case distinctions for PG < 8.2

In PyGres? 5 (the trunk) we support only PG 9.0 and above, so we shouldn't
worry about PG 8.1 and below any more (PG 8.2 was released 10 years ago).
People who need to request old databases can still use PyGres? 4.

Location:
trunk/module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module/pg.py

    r664 r704  
    584584            # if not found, check again in case it was added after we started
    585585            self._pkeys = {}
    586             if self.server_version >= 80200:
    587                 # the ANY syntax works correctly only with PostgreSQL >= 8.2
    588                 any_indkey = "= ANY (pg_index.indkey)"
    589             else:
    590                 any_indkey = "IN (%s)" % ', '.join(
    591                     ['pg_index.indkey[%d]' % i for i in range(16)])
    592586            for r in self.db.query(
    593587                "SELECT pg_namespace.nspname, pg_class.relname,"
     
    600594                " JOIN pg_index ON pg_index.indrelid = pg_class.oid"
    601595                    " AND pg_index.indisprimary = 't'"
    602                     " AND pg_attribute.attnum " + any_indkey).getresult():
     596                    " AND pg_attribute.attnum"
     597                        " = ANY (pg_index.indkey)").getresult():
    603598                cl, pkey = _join_parts(r[:2]), r[2]
    604599                self._pkeys.setdefault(cl, []).append(pkey)
     
    819814        names, values = ', '.join(names), ', '.join(values)
    820815        selectable = self.has_table_privilege(qcl)
    821         if selectable and self.server_version >= 80200:
     816        if selectable:
    822817            ret = ' RETURNING %s*' % ('oid, ' if 'oid' in attnames else '')
    823818        else:
     
    893888        values = ', '.join(values)
    894889        selectable = self.has_table_privilege(qcl)
    895         if selectable and self.server_version >= 80200:
     890        if selectable:
    896891            ret = ' RETURNING %s*' % ('oid, ' if 'oid' in attnames else '')
    897892        else:
  • trunk/module/pgmodule.c

    r703 r704  
    8181
    8282#define MAX_BUFFER_SIZE 8192    /* maximum transaction size */
    83 
    84 #ifndef PG_VERSION_NUM
    85 #ifdef PQnoPasswordSupplied
    86 #define PG_VERSION_NUM 80000
    87 #else
    88 #define PG_VERSION_NUM 70400
    89 #endif
    90 #endif
    91 
    92 /* Before 8.0, PQsetdbLogin was not thread-safe with kerberos. */
    93 #if PG_VERSION_NUM >= 80000 || !(defined(KRB4) || defined(KRB5))
    94 #define PQsetdbLoginIsThreadSafe 1
    95 #endif
    9683
    9784/* MODULE GLOBAL VARIABLES */
     
    24232410        /* backend version */
    24242411        if (!strcmp(name, "server_version"))
    2425 #if PG_VERSION_NUM < 80000
    2426                 return PyInt_FromLong(PG_VERSION_NUM);
    2427 #else
    24282412                return PyInt_FromLong(PQserverVersion(self->cnx));
    2429 #endif
    24302413
    24312414        return PyObject_GenericGetAttr((PyObject *) self, nameobj);
     
    34473430        }
    34483431
    3449 #ifdef PQsetdbLoginIsThreadSafe
    34503432        Py_BEGIN_ALLOW_THREADS
    3451 #endif
    34523433        npgobj->cnx = PQsetdbLogin(pghost, pgport == -1 ? NULL : port_buffer,
    34533434                pgopt, NULL, pgdbname, pguser, pgpasswd);
    3454 #ifdef PQsetdbLoginIsThreadSafe
    34553435        Py_END_ALLOW_THREADS
    3456 #endif
    34573436
    34583437        if (PQstatus(npgobj->cnx) == CONNECTION_BAD)
Note: See TracChangeset for help on using the changeset viewer.