Support SET/SHOW/RESET client_encoding and server_encoding even when
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Oct 2000 19:44:44 +0000 (19:44 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Oct 2000 19:44:44 +0000 (19:44 +0000)
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.

src/backend/commands/variable.c
src/backend/utils/mb/Makefile
src/backend/utils/mb/README
src/backend/utils/mb/variable.c [deleted file]
src/include/mb/pg_wchar.h

index 96a2c126deb4165f2d9429f698422d0ce92579e9..04382cde279a5faccec82dda5b85f8ced8d0a69e 100644 (file)
@@ -9,16 +9,16 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.41 2000/09/22 15:34:31 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.42 2000/10/25 19:44:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
+#include "postgres.h"
+
 #include <ctype.h>
 #include <time.h>
 
-#include "postgres.h"
-
 #include "access/xact.h"
 #include "catalog/pg_shadow.h"
 #include "commands/variable.h"
 
 #ifdef MULTIBYTE
 #include "mb/pg_wchar.h"
+#else
+/* Grand unified hard-coded badness */
+#define pg_encoding_to_char(x) "SQL_ASCII"
+#define pg_get_client_encoding()  0
 #endif
 
 
-
 static bool show_date(void);
 static bool reset_date(void);
 static bool parse_date(char *);
@@ -53,6 +56,13 @@ static bool parse_random_seed(char *);
 static bool show_random_seed(void);
 static bool reset_random_seed(void);
 
+static bool show_client_encoding(void);
+static bool reset_client_encoding(void);
+static bool parse_client_encoding(char *);
+static bool show_server_encoding(void);
+static bool reset_server_encoding(void);
+static bool parse_server_encoding(char *);
+
 
 /*
  * get_token
@@ -250,7 +260,7 @@ parse_date(char *value)
 }
 
 static bool
-show_date()
+show_date(void)
 {
    char        buf[64];
 
@@ -280,7 +290,7 @@ show_date()
 }
 
 static bool
-reset_date()
+reset_date(void)
 {
    DateStyle = DefaultDateStyle;
    EuroDates = DefaultEuroDates;
@@ -379,7 +389,7 @@ parse_timezone(char *value)
 }  /* parse_timezone() */
 
 static bool
-show_timezone()
+show_timezone(void)
 {
    char       *tz;
 
@@ -401,7 +411,7 @@ show_timezone()
  * - thomas 1998-01-26
  */
 static bool
-reset_timezone()
+reset_timezone(void)
 {
    /* no time zone has been set in this session? */
    if (defaultTZ == NULL)
@@ -470,7 +480,7 @@ parse_DefaultXactIsoLevel(char *value)
 }
 
 static bool
-show_DefaultXactIsoLevel()
+show_DefaultXactIsoLevel(void)
 {
 
    if (DefaultXactIsoLevel == XACT_SERIALIZABLE)
@@ -481,7 +491,7 @@ show_DefaultXactIsoLevel()
 }
 
 static bool
-reset_DefaultXactIsoLevel()
+reset_DefaultXactIsoLevel(void)
 {
 #if 0
    TransactionState s = CurrentTransactionState;
@@ -527,7 +537,7 @@ parse_XactIsoLevel(char *value)
 }
 
 static bool
-show_XactIsoLevel()
+show_XactIsoLevel(void)
 {
 
    if (XactIsoLevel == XACT_SERIALIZABLE)
@@ -538,7 +548,7 @@ show_XactIsoLevel()
 }
 
 static bool
-reset_XactIsoLevel()
+reset_XactIsoLevel(void)
 {
 
    if (SerializableSnapshot != NULL)
@@ -588,6 +598,96 @@ reset_random_seed(void)
 }
 
 
+/*
+ * MULTIBYTE-related functions
+ *
+ * If MULTIBYTE support was not compiled, we still allow these variables
+ * to exist, but you can't set them to anything but "SQL_ASCII".  This
+ * minimizes interoperability problems between non-MB servers and MB-enabled
+ * clients.
+ */
+
+static bool
+parse_client_encoding(char *value)
+{
+#ifdef MULTIBYTE
+   int         encoding;
+
+   encoding = pg_valid_client_encoding(value);
+   if (encoding < 0)
+   {
+       if (value)
+           elog(ERROR, "Client encoding %s is not supported", value);
+       else
+           elog(ERROR, "No client encoding is specified");
+   }
+   else
+   {
+       if (pg_set_client_encoding(encoding))
+       {
+           elog(ERROR, "Conversion between %s and %s is not supported",
+                value, pg_encoding_to_char(GetDatabaseEncoding()));
+       }
+   }
+#else
+   if (value &&
+       strcasecmp(value, pg_encoding_to_char(pg_get_client_encoding())) != 0)
+       elog(ERROR, "Client encoding %s is not supported", value);
+#endif
+   return TRUE;
+}
+
+static bool
+show_client_encoding(void)
+{
+   elog(NOTICE, "Current client encoding is %s",
+        pg_encoding_to_char(pg_get_client_encoding()));
+   return TRUE;
+}
+
+static bool
+reset_client_encoding(void)
+{
+#ifdef MULTIBYTE
+   int         encoding;
+   char       *env = getenv("PGCLIENTENCODING");
+
+   if (env)
+   {
+       encoding = pg_char_to_encoding(env);
+       if (encoding < 0)
+           encoding = GetDatabaseEncoding();
+   }
+   else
+       encoding = GetDatabaseEncoding();
+   pg_set_client_encoding(encoding);
+#endif
+   return TRUE;
+}
+
+static bool
+parse_server_encoding(char *value)
+{
+   elog(NOTICE, "SET SERVER_ENCODING is not supported");
+   return TRUE;
+}
+
+static bool
+show_server_encoding(void)
+{
+   elog(NOTICE, "Current server encoding is %s",
+        pg_encoding_to_char(GetDatabaseEncoding()));
+   return TRUE;
+}
+
+static bool
+reset_server_encoding(void)
+{
+   elog(NOTICE, "RESET SERVER_ENCODING is not supported");
+   return TRUE;
+}
+
+
 
 void
 SetPGVariable(const char *name, const char *value)
@@ -606,12 +706,10 @@ SetPGVariable(const char *name, const char *value)
         parse_DefaultXactIsoLevel(mvalue);
     else if (strcasecmp(name, "XactIsoLevel")==0)
         parse_XactIsoLevel(mvalue);
-#ifdef MULTIBYTE
     else if (strcasecmp(name, "client_encoding")==0)
         parse_client_encoding(mvalue);
     else if (strcasecmp(name, "server_encoding")==0)
         parse_server_encoding(mvalue);
-#endif
     else if (strcasecmp(name, "random_seed")==0)
         parse_random_seed(mvalue);
     else
@@ -633,12 +731,10 @@ GetPGVariable(const char *name)
         show_DefaultXactIsoLevel();
     else if (strcasecmp(name, "XactIsoLevel")==0)
         show_XactIsoLevel();
-#ifdef MULTIBYTE
     else if (strcasecmp(name, "client_encoding")==0)
         show_client_encoding();
     else if (strcasecmp(name, "server_encoding")==0)
         show_server_encoding();
-#endif
     else if (strcasecmp(name, "random_seed")==0)
         show_random_seed();
     else
@@ -659,12 +755,10 @@ ResetPGVariable(const char *name)
            reset_DefaultXactIsoLevel();
     else if (strcasecmp(name, "XactIsoLevel")==0)
            reset_XactIsoLevel();
-#ifdef MULTIBYTE
     else if (strcasecmp(name, "client_encoding")==0)
         reset_client_encoding();
     else if (strcasecmp(name, "server_encoding")==0)
         reset_server_encoding();
-#endif
     else if (strcasecmp(name, "random_seed")==0)
         reset_random_seed();
     else
index ecbb151b682f32a8220863260102f8a5a4baaa7f..9efc7281f0f5215cfeddcbd51d4502479a063668 100644 (file)
@@ -4,7 +4,7 @@
 #    Makefile for utils/mb
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.12 2000/10/20 21:03:53 petere Exp $
+#    $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.13 2000/10/25 19:44:44 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -12,8 +12,7 @@ subdir = src/backend/utils/mb
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-OBJS = common.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o \
-       big5.o
+OBJS = common.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
 
 all: SUBSYS.o
 
@@ -22,13 +21,13 @@ SUBSYS.o: $(OBJS)
 
 utftest.o: utftest.c conv.c wchar.c mbutils.c
 
-sjistest: sjistest.o palloc.o common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o variable.o big5.o
+sjistest: sjistest.o palloc.o common.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
    $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
 
 liketest: liketest.o palloc.o $(OBJS)
    $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
 
-utftest: utftest.o palloc.o common.o wstrcmp.o wstrncmp.o variable.o big5.o
+utftest: utftest.o palloc.o common.o wstrcmp.o wstrncmp.o big5.o
    $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
 
 uconv: uconv.o palloc.o common.o conv.o wchar.o big5.o mbutils.o
index dbd0b8da143d57ee8aebfafa9ac2b8caf9300e62..f0d4df958922c8e070103e819e2e09034f5caecf 100644 (file)
@@ -7,7 +7,6 @@ mbutilc.c:  public functions for the backend only.
        requires conv.c and wchar.c
 wstrcmp.c: strcmp for mb
 wstrncmp.c:    strncmp for mb
-varable.c: public functions for show/set/reset variable commands
 alt.c:     a tool to generate KOI8 <--> CP866 conversion table
 iso.c:     a tool to generate KOI8 <--> ISO8859-5 conversion table
 win.c:     a tool to generate KOI8 <--> CP1251 conversion table
diff --git a/src/backend/utils/mb/variable.c b/src/backend/utils/mb/variable.c
deleted file mode 100644 (file)
index 65768ef..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * This file contains some public functions
- * related to show/set/reset variable commands.
- * Tatsuo Ishii
- * $Id: variable.c,v 1.7 2000/04/20 22:40:18 tgl Exp $
- */
-
-#include "postgres.h"
-#include "miscadmin.h"
-#include "mb/pg_wchar.h"
-
-bool
-parse_client_encoding(char *value)
-{
-   int         encoding;
-
-   encoding = pg_valid_client_encoding(value);
-   if (encoding < 0)
-   {
-       if (value)
-           elog(ERROR, "Client encoding %s is not supported", value);
-       else
-           elog(ERROR, "No client encoding is specified");
-   }
-   else
-   {
-       if (pg_set_client_encoding(encoding))
-       {
-           elog(ERROR, "Conversion between %s and %s is not supported",
-                value, pg_encoding_to_char(GetDatabaseEncoding()));
-       }
-   }
-   return TRUE;
-}
-
-bool
-show_client_encoding()
-{
-   elog(NOTICE, "Current client encoding is %s",
-        pg_encoding_to_char(pg_get_client_encoding()));
-   return TRUE;
-}
-
-bool
-reset_client_encoding()
-{
-   int         encoding;
-   char       *env = getenv("PGCLIENTENCODING");
-
-   if (env)
-   {
-       encoding = pg_char_to_encoding(env);
-       if (encoding < 0)
-           encoding = GetDatabaseEncoding();
-   }
-   else
-       encoding = GetDatabaseEncoding();
-   pg_set_client_encoding(encoding);
-   return TRUE;
-}
-
-bool
-parse_server_encoding(char *value)
-{
-   elog(NOTICE, "SET SERVER_ENCODING is not supported");
-   return TRUE;
-}
-
-bool
-show_server_encoding()
-{
-   elog(NOTICE, "Current server encoding is %s",
-        pg_encoding_to_char(GetDatabaseEncoding()));
-   return TRUE;
-}
-
-bool
-reset_server_encoding()
-{
-   elog(NOTICE, "RESET SERVER_ENCODING is not supported");
-   return TRUE;
-}
index c879a4b9e9a8c6d53915fc3b4e362682c139d782..342ea8757e3266fe77aebbc2d660b40d7b8c470c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pg_wchar.h,v 1.19 2000/10/12 07:36:51 ishii Exp $ */
+/* $Id: pg_wchar.h,v 1.20 2000/10/25 19:44:43 tgl Exp $ */
 
 #ifndef PG_WCHAR_H
 #define PG_WCHAR_H
@@ -132,12 +132,6 @@ extern int pg_mbstrlen(const unsigned char *);
 extern int pg_mbstrlen_with_len(const unsigned char *, int);
 extern int pg_mbcliplen(const unsigned char *, int, int);
 extern pg_encoding_conv_tbl *pg_get_encent_by_encoding(int);
-extern bool show_client_encoding(void);
-extern bool reset_client_encoding(void);
-extern bool parse_client_encoding(char *);
-extern bool show_server_encoding(void);
-extern bool reset_server_encoding(void);
-extern bool parse_server_encoding(char *);
 extern int pg_set_client_encoding(int);
 extern int pg_get_client_encoding(void);
 extern unsigned char *pg_client_to_server(unsigned char *, int);