Author: cito
Date: Sat Jan 9 09:48:47 2016
New Revision: 704
Log:
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.
Modified:
trunk/module/pg.py
trunk/module/pgmodule.c
Modified: trunk/module/pg.py
==============================================================================
--- trunk/module/pg.py Fri Jan 8 14:16:26 2016 (r703)
+++ trunk/module/pg.py Sat Jan 9 09:48:47 2016 (r704)
@@ -583,12 +583,6 @@
if qcl not in self._pkeys:
# if not found, check again in case it was added after we started
self._pkeys = {}
- if self.server_version >= 80200:
- # the ANY syntax works correctly only with PostgreSQL >= 8.2
- any_indkey = "= ANY (pg_index.indkey)"
- else:
- any_indkey = "IN (%s)" % ', '.join(
- ['pg_index.indkey[%d]' % i for i in range(16)])
for r in self.db.query(
"SELECT pg_namespace.nspname, pg_class.relname,"
" pg_attribute.attname FROM pg_class"
@@ -599,7 +593,8 @@
" AND pg_attribute.attisdropped = 'f'"
" JOIN pg_index ON pg_index.indrelid = pg_class.oid"
" AND pg_index.indisprimary = 't'"
- " AND pg_attribute.attnum " + any_indkey).getresult():
+ " AND pg_attribute.attnum"
+ " = ANY (pg_index.indkey)").getresult():
cl, pkey = _join_parts(r[:2]), r[2]
self._pkeys.setdefault(cl, []).append(pkey)
# (only) for composite primary keys, the values will be frozensets
@@ -818,7 +813,7 @@
values.append(self._quote(d[n], attnames[n]))
names, values = ', '.join(names), ', '.join(values)
selectable = self.has_table_privilege(qcl)
- if selectable and self.server_version >= 80200:
+ if selectable:
ret = ' RETURNING %s*' % ('oid, ' if 'oid' in attnames else '')
else:
ret = ''
@@ -892,7 +887,7 @@
return d
values = ', '.join(values)
selectable = self.has_table_privilege(qcl)
- if selectable and self.server_version >= 80200:
+ if selectable:
ret = ' RETURNING %s*' % ('oid, ' if 'oid' in attnames else '')
else:
ret = ''
Modified: trunk/module/pgmodule.c
==============================================================================
--- trunk/module/pgmodule.c Fri Jan 8 14:16:26 2016 (r703)
+++ trunk/module/pgmodule.c Sat Jan 9 09:48:47 2016 (r704)
@@ -81,19 +81,6 @@
#define MAX_BUFFER_SIZE 8192 /* maximum transaction size */
-#ifndef PG_VERSION_NUM
-#ifdef PQnoPasswordSupplied
-#define PG_VERSION_NUM 80000
-#else
-#define PG_VERSION_NUM 70400
-#endif
-#endif
-
-/* Before 8.0, PQsetdbLogin was not thread-safe with kerberos. */
-#if PG_VERSION_NUM >= 80000 || !(defined(KRB4) || defined(KRB5))
-#define PQsetdbLoginIsThreadSafe 1
-#endif
-
/* MODULE GLOBAL VARIABLES */
#ifdef DEFAULT_VARS
@@ -2422,11 +2409,7 @@
/* backend version */
if (!strcmp(name, "server_version"))
-#if PG_VERSION_NUM < 80000
- return PyInt_FromLong(PG_VERSION_NUM);
-#else
return PyInt_FromLong(PQserverVersion(self->cnx));
-#endif
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
@@ -3446,14 +3429,10 @@
sprintf(port_buffer, "%d", pgport);
}
-#ifdef PQsetdbLoginIsThreadSafe
Py_BEGIN_ALLOW_THREADS
-#endif
npgobj->cnx = PQsetdbLogin(pghost, pgport == -1 ? NULL : port_buffer,
pgopt, NULL, pgdbname, pguser, pgpasswd);
-#ifdef PQsetdbLoginIsThreadSafe
Py_END_ALLOW_THREADS
-#endif
if (PQstatus(npgobj->cnx) == CONNECTION_BAD)
{
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql