mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
Fix the inadvertent libpq ABI breakage discovered by Martin Pitt: the
renumbering of encoding IDs done between 8.2 and 8.3 turns out to break 8.2 initdb and psql if they are run with an 8.3beta1 libpq.so. For the moment we can rearrange the order of enum pg_enc to keep the same number for everything except PG_JOHAB, which isn't a problem since there are no direct references to it in the 8.2 programs anyway. (This does force initdb unfortunately.) Going forward, we want to fix things so that encoding IDs can be changed without an ABI break, and this commit includes the changes needed to allow libpq's encoding IDs to be treated as fully independent of the backend's. The main issue is that libpq clients should not include pg_wchar.h or otherwise assume they know the specific values of libpq's encoding IDs, since they might encounter version skew between pg_wchar.h and the libpq.so they are using. To fix, have libpq officially export functions needed for encoding name<=>ID conversion and validity checking; it was doing this anyway unofficially. It's still the case that we can't renumber backend encoding IDs until the next bump in libpq's major version number, since doing so will break the 8.2-era client programs. However the code is now prepared to avoid this type of problem in future. Note that initdb is no longer a libpq client: we just pull in the two source files we need directly. The patch also fixes a few places that were being sloppy about checking for an unrecognized encoding name.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.16 2007/07/08 17:11:51 joe Exp $
|
||||
# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.17 2007/10/13 20:18:41 tgl Exp $
|
||||
# Functions to be exported by libpq DLLs
|
||||
PQconnectdb 1
|
||||
PQsetdbLogin 2
|
||||
@@ -138,3 +138,4 @@ PQsendDescribePrepared 135
|
||||
PQsendDescribePortal 136
|
||||
lo_truncate 137
|
||||
PQconnectionUsedPassword 138
|
||||
pg_valid_server_encoding_id 139
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.192 2007/01/05 22:20:01 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.193 2007/10/13 20:18:42 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -630,11 +630,14 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
|
||||
* standard_conforming_strings, and convert server version to a numeric
|
||||
* form. We keep the first two of these in static variables as well, so
|
||||
* that PQescapeString and PQescapeBytea can behave somewhat sanely (at
|
||||
* least in single- connection-using programs).
|
||||
* least in single-connection-using programs).
|
||||
*/
|
||||
if (strcmp(name, "client_encoding") == 0)
|
||||
{
|
||||
conn->client_encoding = pg_char_to_encoding(value);
|
||||
/* if we don't recognize the encoding name, fall back to SQL_ASCII */
|
||||
if (conn->client_encoding < 0)
|
||||
conn->client_encoding = PG_SQL_ASCII;
|
||||
static_client_encoding = conn->client_encoding;
|
||||
}
|
||||
else if (strcmp(name, "standard_conforming_strings") == 0)
|
||||
|
@@ -23,7 +23,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.131 2007/01/05 22:20:01 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.132 2007/10/13 20:18:42 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1112,7 +1112,11 @@ PQenv2encoding(void)
|
||||
|
||||
str = getenv("PGCLIENTENCODING");
|
||||
if (str && *str != '\0')
|
||||
{
|
||||
encoding = pg_char_to_encoding(str);
|
||||
if (encoding < 0)
|
||||
encoding = PG_SQL_ASCII;
|
||||
}
|
||||
return encoding;
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.138 2007/07/08 18:28:55 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.139 2007/10/13 20:18:42 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -511,6 +511,12 @@ extern int PQenv2encoding(void);
|
||||
|
||||
extern char *PQencryptPassword(const char *passwd, const char *user);
|
||||
|
||||
/* === in encnames.c === */
|
||||
|
||||
extern int pg_char_to_encoding(const char *name);
|
||||
extern const char *pg_encoding_to_char(int encoding);
|
||||
extern int pg_valid_server_encoding_id(int encoding);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user