correctly. See following thread for more details.
Subject: [HACKERS] client_encoding directive is ignored in postgresql.conf
From: Tatsuo Ishii <t-ishii@sra.co.jp>
Date: Wed, 29 Jan 2003 22:24:04 +0900 (JST)
index 3ad2c50a84387fca9d53b4897d74e2534b8d4660..36dd3c7b5c2c3fa1f6e7acbe54740c48b7b09773 100644 (file)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.118 2002年11月21日 06:36:08 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.119 2003年02月19日 14:31:26 ishii Exp $
*
*
*-------------------------------------------------------------------------
@@ -397,6 +397,9 @@ InitPostgres(const char *dbname, const char *username)
/* set default namespace search path */
InitializeSearchPath();
+ /* initialize client encoding */
+ InitializeClientEncoding();
+
/*
* Set up process-exit callback to do pre-shutdown cleanup. This
* should be last because we want shmem_exit to call this routine
index d66444d78d8c2d4f6aae1a36f6b5bd7b06282544..560dffa858149df2eda4e08cf86962e233545828 100644 (file)
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
*
- * $Header: /cvsroot/pgsql/src/backend/utils/mb/mbutils.c,v 1.37 2002年11月26日 02:22:29 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/mb/mbutils.c,v 1.38 2003年02月19日 14:31:26 ishii Exp $
*/
#include "postgres.h"
@@ -37,6 +37,8 @@ static unsigned char *perform_default_encoding_conversion(unsigned char *src,
int len, bool is_client_to_server);
static int cliplen(const unsigned char *str, int len, int limit);
+/* Flag to we need to initialize client encoding info */
+static bool need_to_init_client_encoding = -1;
/*
* Set the client encoding and save fmgrinfo for the converion
@@ -58,6 +60,13 @@ SetClientEncoding(int encoding, bool doit)
if (!PG_VALID_FE_ENCODING(encoding))
return (-1);
+ /* If we cannot actualy set client encoding info, remeber it
+ * so that we could set it using InitializeClientEncoding()
+ * in InitPostgres()
+ */
+ if (current_server_encoding != encoding && !IsTransactionState())
+ need_to_init_client_encoding = encoding;
+
if (current_server_encoding == encoding ||
(current_server_encoding == PG_SQL_ASCII || encoding == PG_SQL_ASCII))
{
return 0;
}
+/* Initialize client encoding if necessary.
+ * called from InitPostgres() once during backend starting up.
+ */
+void
+InitializeClientEncoding()
+{
+ if (need_to_init_client_encoding > 0)
+ {
+ SetClientEncoding(need_to_init_client_encoding, 1);
+ need_to_init_client_encoding = -1;
+ }
+}
+
/*
* returns the current client encoding */
int
index a73a16277b549efb9cb4323dbd65c0702114ee89..3df5e3eab7fcd2332f706db6d5e45af6b0e49a0e 100644 (file)
-/* $Id: pg_wchar.h,v 1.44 2002年09月04日 20:31:42 momjian Exp $ */
+/* $Id: pg_wchar.h,v 1.45 2003年02月19日 14:31:26 ishii Exp $ */
#ifndef PG_WCHAR_H
#define PG_WCHAR_H
@@ -295,6 +295,7 @@ extern int pg_database_encoding_max_length(void);
extern void SetDefaultClientEncoding(void);
extern int SetClientEncoding(int encoding, bool doit);
+extern void InitializeClientEncoding(void);
extern int pg_get_client_encoding(void);
extern const char *pg_get_client_encoding_name(void);
index dd651fd2132ea003946e6ad82624c32fab57ac8b..32ef6e115a5847223caef943c3889bedbf56e6e7 100644 (file)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.223 2003年02月14日 01:24:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.224 2003年02月19日 14:31:26 ishii Exp $
*
*-------------------------------------------------------------------------
*/
* server for it. We must use begin/commit in
* case autocommit is off by default.
*/
- if (!PQsendQuery(conn, "begin; select getdatabaseencoding(); commit"))
+ if (!PQsendQuery(conn, "begin; select pg_client_encoding(); commit"))
goto error_return;
conn->setenv_state = SETENV_STATE_ENCODINGS_WAIT;