From 73265e7ece3ca5e6eba1ec8b4234e5884905aafc Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 16 Nov 2010 00:42:23 +0000 Subject: [PATCH] Refuse connection with server with protocol version 2. This cuts off server whose version is older than 7.4. But enables us to remove large portions of code rarely used and tested (e.g. p2 copy) and will allow us to drop the query we do at each connection to establish the client encoding and the datestyle. --- ChangeLog | 4 ++++ NEWS-2.3 | 2 ++ doc/src/connection.rst | 4 +++- psycopg/connection_int.c | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cc318ff2..244710cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-11-16 Daniele Varrazzo + + * psycopg/connection_int.c: abort connection to protocol 2 server. + 2010-11-11 Daniele Varrazzo * lib/extras.py: build the namedtuple only once per execution, not once diff --git a/NEWS-2.3 b/NEWS-2.3 index 87f03ca1..bf1e628b 100644 --- a/NEWS-2.3 +++ b/NEWS-2.3 @@ -13,6 +13,8 @@ psycopg 2.3 aims to expose some new features introduced in PostgreSQL 9.0. * Other features and changes: + - Dropped support for protocol 2: Psycopg 2.3 can only connect to PostgreSQL + servers with version at least 7.4. - `mogrify()` now supports unicode queries. - subclasses of a type that can be adapted are adapted as the superclass. - `errorcodes` knows a couple of new codes introduced in PostgreSQL 9.0. diff --git a/doc/src/connection.rst b/doc/src/connection.rst index 624fcba7..22241fed 100644 --- a/doc/src/connection.rst +++ b/doc/src/connection.rst @@ -428,7 +428,9 @@ The ``connection`` class .. attribute:: protocol_version A read-only integer representing frontend/backend protocol being used. - It can be 2 or 3. + Currently Psycopg supports only protocol 3, which allows connection + to PostgreSQL server from version 7.4. Psycopg versions previous than + 2.3 support both protocols 2 and 3. .. seealso:: libpq docs for `PQprotocolVersion()`__ for details. diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 7f864608..e335c396 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -295,6 +295,10 @@ conn_setup(connectionObject *self, PGconn *pgconn) self->equote = conn_get_standard_conforming_strings(pgconn); self->server_version = conn_get_server_version(pgconn); self->protocol = conn_get_protocol_version(self->pgconn); + if (3 != self->protocol) { + PyErr_SetString(InterfaceError, "only protocol 3 supported"); + return -1; + } Py_BEGIN_ALLOW_THREADS; pthread_mutex_lock(&self->lock); @@ -636,6 +640,10 @@ _conn_poll_setup_async(connectionObject *self) self->equote = conn_get_standard_conforming_strings(self->pgconn); self->protocol = conn_get_protocol_version(self->pgconn); self->server_version = conn_get_server_version(self->pgconn); + if (3 != self->protocol) { + PyErr_SetString(InterfaceError, "only protocol 3 supported"); + break; + } /* asynchronous connections always use isolation level 0, the user is * expected to manage the transactions himself, by sending