Do not pass server_encoding to the client.

libpq, talking to an old server, should assume SQL_ASCII as the default
client encoding, because that is what the server will actually use (not
the server encoding).
This commit is contained in:
Peter Eisentraut 2003-09-01 23:04:49 +00:00
parent f10a9033bf
commit 5f65345a57
4 changed files with 22 additions and 34 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.133 2003/08/31 17:32:19 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.134 2003/09/01 23:04:49 petere Exp $
--> -->
<chapter id="libpq"> <chapter id="libpq">
@ -856,21 +856,20 @@ is not known.
<para> <para>
Parameters reported as of the current release include Parameters reported as of the current release include
<literal>server_version</> (cannot change after startup); <literal>server_version</> (cannot change after startup);
<literal>server_encoding</> (also not presently changeable after start);
<literal>client_encoding</>, <literal>client_encoding</>,
<literal>is_superuser</>, and <literal>is_superuser</>, and
<literal>DateStyle</>. <literal>DateStyle</>.
</para> </para>
<para> <para>
Pre-3.0-protocol servers do not report parameter settings, Pre-3.0-protocol servers do not report parameter settings, but
but <application>libpq</> includes logic to obtain values for <application>libpq</> includes logic to obtain values for
<literal>server_version</>, <literal>server_encoding</>, and <literal>server_version</>, and <literal>client_encoding</>.
<literal>client_encoding</>. Applications are encouraged to use Applications are encouraged to use <function>PQparameterStatus</>
<function>PQparameterStatus</> rather than ad-hoc code to determine these rather than ad-hoc code to determine these values. (Beware however
values. (Beware however that on a pre-3.0 connection, changing that on a pre-3.0 connection, changing <literal>client_encoding</> via
<literal>client_encoding</> via <command>SET</> after connection startup <command>SET</> after connection startup will not be reflected by
will not be reflected by <function>PQparameterStatus</>.) <function>PQparameterStatus</>.)
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -1,4 +1,4 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.41 2003/08/14 20:09:31 tgl Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/protocol.sgml,v 1.42 2003/09/01 23:04:49 petere Exp $ -->
<chapter id="protocol"> <chapter id="protocol">
<title>Frontend/Backend Protocol</title> <title>Frontend/Backend Protocol</title>
@ -1005,7 +1005,6 @@
ParameterStatus will be generated: they are ParameterStatus will be generated: they are
<literal>server_version</> (a pseudo-parameter that cannot change after <literal>server_version</> (a pseudo-parameter that cannot change after
startup); startup);
<literal>server_encoding</> (also not presently changeable after start);
<literal>client_encoding</>, <literal>client_encoding</>,
<literal>is_superuser</>, and <literal>is_superuser</>, and
<literal>DateStyle</>. <literal>DateStyle</>.

View File

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.152 2003/09/01 04:15:50 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.153 2003/09/01 23:04:49 petere Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
@ -1479,7 +1479,7 @@ static struct config_string ConfigureNamesString[] =
{"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE, {"server_encoding", PGC_INTERNAL, CLIENT_CONN_LOCALE,
gettext_noop("Server (database) character set encoding"), gettext_noop("Server (database) character set encoding"),
NULL, NULL,
GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
}, },
&server_encoding_string, &server_encoding_string,
"SQL_ASCII", NULL, NULL "SQL_ASCII", NULL, NULL

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.7 2003/08/27 00:33:34 petere Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.8 2003/09/01 23:04:49 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -177,10 +177,10 @@ pqSetenvPoll(PGconn *conn)
* must use begin/commit in case autocommit is off by * must use begin/commit in case autocommit is off by
* default in a 7.3 server. * default in a 7.3 server.
* *
* Note: version() and getdatabaseencoding() exist in all * Note: version() exists in all
* protocol-2.0-supporting backends. * protocol-2.0-supporting backends.
*/ */
if (!PQsendQuery(conn, "begin; select version(), getdatabaseencoding(); end")) if (!PQsendQuery(conn, "begin; select version(); end"))
goto error_return; goto error_return;
conn->setenv_state = SETENV_STATE_QUERY1_WAIT; conn->setenv_state = SETENV_STATE_QUERY1_WAIT;
@ -213,8 +213,8 @@ pqSetenvPoll(PGconn *conn)
} }
/* /*
* Extract server version and database encoding, * Extract server version and save as if
* and save as if ParameterStatus * ParameterStatus
*/ */
val = PQgetvalue(res, 0, 0); val = PQgetvalue(res, 0, 0);
if (val && strncmp(val, "PostgreSQL ", 11) == 0) if (val && strncmp(val, "PostgreSQL ", 11) == 0)
@ -236,12 +236,6 @@ pqSetenvPoll(PGconn *conn)
val); val);
} }
val = PQgetvalue(res, 0, 1);
if (val && *val) /* null should not happen,
* but */
pqSaveParameterStatus(conn, "server_encoding",
val);
PQclear(res); PQclear(res);
/* Keep reading until PQgetResult returns NULL */ /* Keep reading until PQgetResult returns NULL */
} }
@ -306,21 +300,17 @@ pqSetenvPoll(PGconn *conn)
else else
{ {
/* /*
* Error: presumably function not available, * Error: presumably function not
* so use PGCLIENTENCODING or database * available, so use PGCLIENTENCODING or
* encoding as the fallback. * SQL_ASCII as the fallback.
*/ */
val = getenv("PGCLIENTENCODING"); val = getenv("PGCLIENTENCODING");
if (val && *val) if (val && *val)
pqSaveParameterStatus(conn, "client_encoding", pqSaveParameterStatus(conn, "client_encoding",
val); val);
else else
{ pqSaveParameterStatus(conn, "client_encoding",
val = PQparameterStatus(conn, "server_encoding"); "SQL_ASCII");
if (val && *val)
pqSaveParameterStatus(conn, "client_encoding",
val);
}
} }
PQclear(res); PQclear(res);