Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0a63b6d

Browse files
committed
Support SET/SHOW/RESET client_encoding and server_encoding even when
MULTIBYTE support is not compiled (you just can't set them to anything but SQL_ASCII). This should reduce interoperability problems between MB-enabled clients and non-MB-enabled servers.
1 parent 995ccad commit 0a63b6d

File tree

5 files changed

+117
-113
lines changed

5 files changed

+117
-113
lines changed

src/backend/commands/variable.c

Lines changed: 112 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.41 2000/09/22 15:34:31 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.42 2000/10/25 19:44:44 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616

17+
#include "postgres.h"
18+
1719
#include <ctype.h>
1820
#include <time.h>
1921

20-
#include "postgres.h"
21-
2222
#include "access/xact.h"
2323
#include "catalog/pg_shadow.h"
2424
#include "commands/variable.h"
@@ -32,10 +32,13 @@
3232

3333
#ifdef MULTIBYTE
3434
#include "mb/pg_wchar.h"
35+
#else
36+
/* Grand unified hard-coded badness */
37+
#define pg_encoding_to_char(x) "SQL_ASCII"
38+
#define pg_get_client_encoding() 0
3539
#endif
3640

3741

38-
3942
static bool show_date(void);
4043
static bool reset_date(void);
4144
static bool parse_date(char *);
@@ -53,6 +56,13 @@ static bool parse_random_seed(char *);
5356
static bool show_random_seed(void);
5457
static bool reset_random_seed(void);
5558

59+
static bool show_client_encoding(void);
60+
static bool reset_client_encoding(void);
61+
static bool parse_client_encoding(char *);
62+
static bool show_server_encoding(void);
63+
static bool reset_server_encoding(void);
64+
static bool parse_server_encoding(char *);
65+
5666

5767
/*
5868
* get_token
@@ -250,7 +260,7 @@ parse_date(char *value)
250260
}
251261

252262
static bool
253-
show_date()
263+
show_date(void)
254264
{
255265
char buf[64];
256266

@@ -280,7 +290,7 @@ show_date()
280290
}
281291

282292
static bool
283-
reset_date()
293+
reset_date(void)
284294
{
285295
DateStyle = DefaultDateStyle;
286296
EuroDates = DefaultEuroDates;
@@ -379,7 +389,7 @@ parse_timezone(char *value)
379389
} /* parse_timezone() */
380390

381391
static bool
382-
show_timezone()
392+
show_timezone(void)
383393
{
384394
char *tz;
385395

@@ -401,7 +411,7 @@ show_timezone()
401411
* - thomas 1998-01-26
402412
*/
403413
static bool
404-
reset_timezone()
414+
reset_timezone(void)
405415
{
406416
/* no time zone has been set in this session? */
407417
if (defaultTZ == NULL)
@@ -470,7 +480,7 @@ parse_DefaultXactIsoLevel(char *value)
470480
}
471481

472482
static bool
473-
show_DefaultXactIsoLevel()
483+
show_DefaultXactIsoLevel(void)
474484
{
475485

476486
if (DefaultXactIsoLevel == XACT_SERIALIZABLE)
@@ -481,7 +491,7 @@ show_DefaultXactIsoLevel()
481491
}
482492

483493
static bool
484-
reset_DefaultXactIsoLevel()
494+
reset_DefaultXactIsoLevel(void)
485495
{
486496
#if 0
487497
TransactionState s = CurrentTransactionState;
@@ -527,7 +537,7 @@ parse_XactIsoLevel(char *value)
527537
}
528538

529539
static bool
530-
show_XactIsoLevel()
540+
show_XactIsoLevel(void)
531541
{
532542

533543
if (XactIsoLevel == XACT_SERIALIZABLE)
@@ -538,7 +548,7 @@ show_XactIsoLevel()
538548
}
539549

540550
static bool
541-
reset_XactIsoLevel()
551+
reset_XactIsoLevel(void)
542552
{
543553

544554
if (SerializableSnapshot != NULL)
@@ -588,6 +598,96 @@ reset_random_seed(void)
588598
}
589599

590600

601+
/*
602+
* MULTIBYTE-related functions
603+
*
604+
* If MULTIBYTE support was not compiled, we still allow these variables
605+
* to exist, but you can't set them to anything but "SQL_ASCII". This
606+
* minimizes interoperability problems between non-MB servers and MB-enabled
607+
* clients.
608+
*/
609+
610+
static bool
611+
parse_client_encoding(char *value)
612+
{
613+
#ifdef MULTIBYTE
614+
int encoding;
615+
616+
encoding = pg_valid_client_encoding(value);
617+
if (encoding < 0)
618+
{
619+
if (value)
620+
elog(ERROR, "Client encoding %s is not supported", value);
621+
else
622+
elog(ERROR, "No client encoding is specified");
623+
}
624+
else
625+
{
626+
if (pg_set_client_encoding(encoding))
627+
{
628+
elog(ERROR, "Conversion between %s and %s is not supported",
629+
value, pg_encoding_to_char(GetDatabaseEncoding()));
630+
}
631+
}
632+
#else
633+
if (value &&
634+
strcasecmp(value, pg_encoding_to_char(pg_get_client_encoding())) != 0)
635+
elog(ERROR, "Client encoding %s is not supported", value);
636+
#endif
637+
return TRUE;
638+
}
639+
640+
static bool
641+
show_client_encoding(void)
642+
{
643+
elog(NOTICE, "Current client encoding is %s",
644+
pg_encoding_to_char(pg_get_client_encoding()));
645+
return TRUE;
646+
}
647+
648+
static bool
649+
reset_client_encoding(void)
650+
{
651+
#ifdef MULTIBYTE
652+
int encoding;
653+
char *env = getenv("PGCLIENTENCODING");
654+
655+
if (env)
656+
{
657+
encoding = pg_char_to_encoding(env);
658+
if (encoding < 0)
659+
encoding = GetDatabaseEncoding();
660+
}
661+
else
662+
encoding = GetDatabaseEncoding();
663+
pg_set_client_encoding(encoding);
664+
#endif
665+
return TRUE;
666+
}
667+
668+
static bool
669+
parse_server_encoding(char *value)
670+
{
671+
elog(NOTICE, "SET SERVER_ENCODING is not supported");
672+
return TRUE;
673+
}
674+
675+
static bool
676+
show_server_encoding(void)
677+
{
678+
elog(NOTICE, "Current server encoding is %s",
679+
pg_encoding_to_char(GetDatabaseEncoding()));
680+
return TRUE;
681+
}
682+
683+
static bool
684+
reset_server_encoding(void)
685+
{
686+
elog(NOTICE, "RESET SERVER_ENCODING is not supported");
687+
return TRUE;
688+
}
689+
690+
591691

592692
void
593693
SetPGVariable(const char *name, const char *value)
@@ -606,12 +706,10 @@ SetPGVariable(const char *name, const char *value)
606706
parse_DefaultXactIsoLevel(mvalue);
607707
else if (strcasecmp(name, "XactIsoLevel")==0)
608708
parse_XactIsoLevel(mvalue);
609-
#ifdef MULTIBYTE
610709
else if (strcasecmp(name, "client_encoding")==0)
611710
parse_client_encoding(mvalue);
612711
else if (strcasecmp(name, "server_encoding")==0)
613712
parse_server_encoding(mvalue);
614-
#endif
615713
else if (strcasecmp(name, "random_seed")==0)
616714
parse_random_seed(mvalue);
617715
else
@@ -633,12 +731,10 @@ GetPGVariable(const char *name)
633731
show_DefaultXactIsoLevel();
634732
else if (strcasecmp(name, "XactIsoLevel")==0)
635733
show_XactIsoLevel();
636-
#ifdef MULTIBYTE
637734
else if (strcasecmp(name, "client_encoding")==0)
638735
show_client_encoding();
639736
else if (strcasecmp(name, "server_encoding")==0)
640737
show_server_encoding();
641-
#endif
642738
else if (strcasecmp(name, "random_seed")==0)
643739
show_random_seed();
644740
else
@@ -659,12 +755,10 @@ ResetPGVariable(const char *name)
659755
reset_DefaultXactIsoLevel();
660756
else if (strcasecmp(name, "XactIsoLevel")==0)
661757
reset_XactIsoLevel();
662-
#ifdef MULTIBYTE
663758
else if (strcasecmp(name, "client_encoding")==0)
664759
reset_client_encoding();
665760
else if (strcasecmp(name, "server_encoding")==0)
666761
reset_server_encoding();
667-
#endif
668762
else if (strcasecmp(name, "random_seed")==0)
669763
reset_random_seed();
670764
else

src/backend/utils/mb/Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
# Makefile for utils/mb
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.12 2000/10/20 21:03:53 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.13 2000/10/25 19:44:44 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

1111
subdir = src/backend/utils/mb
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = common.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o \
16-
big5.o
15+
OBJS = common.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
1716

1817
all: SUBSYS.o
1918

@@ -22,13 +21,13 @@ SUBSYS.o: $(OBJS)
2221

2322
utftest.o: utftest.c conv.c wchar.c mbutils.c
2423

25-
sjistest: sjistest.o palloc.o common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o big5.o
24+
sjistest: sjistest.o palloc.o common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
2625
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
2726

2827
liketest: liketest.o palloc.o $(OBJS)
2928
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
3029

31-
utftest: utftest.o palloc.o common.o wstrcmp.o wstrncmp.o variable.o big5.o
30+
utftest: utftest.o palloc.o common.o wstrcmp.o wstrncmp.o big5.o
3231
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
3332

3433
uconv: uconv.o palloc.o common.o conv.o wchar.o big5.o mbutils.o

src/backend/utils/mb/README

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mbutilc.c: public functions for the backend only.
77
requires conv.c and wchar.c
88
wstrcmp.c: strcmp for mb
99
wstrncmp.c: strncmp for mb
10-
varable.c: public functions for show/set/reset variable commands
1110
alt.c: a tool to generate KOI8 <--> CP866 conversion table
1211
iso.c: a tool to generate KOI8 <--> ISO8859-5 conversion table
1312
win.c: a tool to generate KOI8 <--> CP1251 conversion table

src/backend/utils/mb/variable.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)