]> granicus.if.org Git - postgresql/commitdiff
Add new backslash command \eset and \eshow.
authorTatsuo Ishii <ishii@postgresql.org>
Sat, 19 Feb 2000 05:01:16 +0000 (05:01 +0000)
committerTatsuo Ishii <ishii@postgresql.org>
Sat, 19 Feb 2000 05:01:16 +0000 (05:01 +0000)
src/bin/psql/command.c
src/bin/psql/help.c

index a4353124cc31267002533fcf14216cae73a7389e..cf1e701c0e19cecd20df057e3eaa2381cdea1138 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.19 2000/02/16 13:15:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.20 2000/02/19 05:01:15 ishii Exp $
  */
 #include "postgres.h"
 #include "command.h"
 #include "settings.h"
 #include "variables.h"
 
+#ifdef MULTIBYTE
+#include "miscadmin.h"
+#include "mb/pg_wchar.h"
+#endif
+
 
 /* functions for use in this file */
 
@@ -346,6 +351,30 @@ exec_command(const char *cmd,
             fputs("\n", fout);
        }
 
+#ifdef MULTIBYTE
+       /* \eset -- set client side encoding */
+       else if (strcmp(cmd, "eset") == 0)
+       {
+               char *encoding = scan_option(&string, OT_NORMAL, NULL);
+               if (PQsetClientEncoding(pset.db, encoding) == -1)
+               {
+                       psql_error("\\%s: invalid encoding\n", cmd);
+               }
+               /* save encoding info into psql internal data */
+               pset.encoding = PQclientEncoding(pset.db);
+               free(encoding);
+       }
+       /* \eshow -- show encoding info */
+       else if (strcmp(cmd, "eshow") == 0)
+       {
+               int encoding = PQclientEncoding(pset.db);
+               if (encoding == -1)
+               {
+                       psql_error("\\%s: there is no connection\n", cmd);
+               }
+               printf("%s\n", pg_encoding_to_char(encoding));
+       }
+#endif
        /* \f -- change field separator */
        else if (strcmp(cmd, "f") == 0)
     {
index 63e4bda5d74d3eb5d50e24edab94cfd9f8c6d126..ddd8b22c3506e057084dd1df0875d968164094f1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.19 2000/02/16 13:15:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.20 2000/02/19 05:01:16 ishii Exp $
  */
 #include "postgres.h"
 #include "help.h"
@@ -200,6 +200,10 @@ slashUsage(void)
        fprintf(fout, " \\dT            list data types\n");
        fprintf(fout, " \\e [fname]     edit the current query buffer or <fname> with external editor\n");
        fprintf(fout, " \\echo <text>   write text to stdout\n");
+#ifdef MULTIBYTE
+       fprintf(fout, " \\eset <encoding> set client encoding\n");
+       fprintf(fout, " \\eshow         show client encoding\n");
+#endif
        fprintf(fout, " \\g [fname]     send query to backend (and results in <fname> or |pipe)\n");
        fprintf(fout, " \\h [cmd]       help on syntax of sql commands, * for all commands\n");
        fprintf(fout, " \\i <fname>     read and execute queries from filename\n");