Skip to content

Commit e2a618f

Browse files
committed
Fix for GUC client_encoding variable not being handled
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)
1 parent d5740d7 commit e2a618f

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/backend/utils/init/postinit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.118 2002/11/21 06:36:08 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.119 2003/02/19 14:31:26 ishii Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -397,6 +397,9 @@ InitPostgres(const char *dbname, const char *username)
397397
/* set default namespace search path */
398398
InitializeSearchPath();
399399

400+
/* initialize client encoding */
401+
InitializeClientEncoding();
402+
400403
/*
401404
* Set up process-exit callback to do pre-shutdown cleanup. This
402405
* should be last because we want shmem_exit to call this routine

src/backend/utils/mb/mbutils.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* (currently mule internal code (mic) is used)
55
* Tatsuo Ishii
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/mb/mbutils.c,v 1.37 2002/11/26 02:22:29 ishii Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/mb/mbutils.c,v 1.38 2003/02/19 14:31:26 ishii Exp $
88
*/
99
#include "postgres.h"
1010

@@ -37,6 +37,8 @@ static unsigned char *perform_default_encoding_conversion(unsigned char *src,
3737
int len, bool is_client_to_server);
3838
static int cliplen(const unsigned char *str, int len, int limit);
3939

40+
/* Flag to we need to initialize client encoding info */
41+
static bool need_to_init_client_encoding = -1;
4042

4143
/*
4244
* Set the client encoding and save fmgrinfo for the converion
@@ -58,6 +60,13 @@ SetClientEncoding(int encoding, bool doit)
5860
if (!PG_VALID_FE_ENCODING(encoding))
5961
return (-1);
6062

63+
/* If we cannot actualy set client encoding info, remeber it
64+
* so that we could set it using InitializeClientEncoding()
65+
* in InitPostgres()
66+
*/
67+
if (current_server_encoding != encoding && !IsTransactionState())
68+
need_to_init_client_encoding = encoding;
69+
6170
if (current_server_encoding == encoding ||
6271
(current_server_encoding == PG_SQL_ASCII || encoding == PG_SQL_ASCII))
6372
{
@@ -115,6 +124,19 @@ SetClientEncoding(int encoding, bool doit)
115124
return 0;
116125
}
117126

127+
/* Initialize client encoding if necessary.
128+
* called from InitPostgres() once during backend starting up.
129+
*/
130+
void
131+
InitializeClientEncoding()
132+
{
133+
if (need_to_init_client_encoding > 0)
134+
{
135+
SetClientEncoding(need_to_init_client_encoding, 1);
136+
need_to_init_client_encoding = -1;
137+
}
138+
}
139+
118140
/*
119141
* returns the current client encoding */
120142
int

src/include/mb/pg_wchar.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Id: pg_wchar.h,v 1.44 2002/09/04 20:31:42 momjian Exp $ */
1+
/* $Id: pg_wchar.h,v 1.45 2003/02/19 14:31:26 ishii Exp $ */
22

33
#ifndef PG_WCHAR_H
44
#define PG_WCHAR_H
@@ -295,6 +295,7 @@ extern int pg_database_encoding_max_length(void);
295295

296296
extern void SetDefaultClientEncoding(void);
297297
extern int SetClientEncoding(int encoding, bool doit);
298+
extern void InitializeClientEncoding(void);
298299
extern int pg_get_client_encoding(void);
299300
extern const char *pg_get_client_encoding_name(void);
300301

src/interfaces/libpq/fe-connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.223 2003/02/14 01:24:26 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.224 2003/02/19 14:31:26 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1744,7 +1744,7 @@ PQsetenvPoll(PGconn *conn)
17441744
* server for it. We must use begin/commit in
17451745
* case autocommit is off by default.
17461746
*/
1747-
if (!PQsendQuery(conn, "begin; select getdatabaseencoding(); commit"))
1747+
if (!PQsendQuery(conn, "begin; select pg_client_encoding(); commit"))
17481748
goto error_return;
17491749

17501750
conn->setenv_state = SETENV_STATE_ENCODINGS_WAIT;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy