Skip to content

Commit eb089e7

Browse files
committed
Add new backslash command \eset and \eshow.
1 parent c239c11 commit eb089e7

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/bin/psql/command.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.19 2000/02/16 13:15:26 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.20 2000/02/19 05:01:15 ishii Exp $
77
*/
88
#include "postgres.h"
99
#include "command.h"
@@ -33,6 +33,11 @@
3333
#include "settings.h"
3434
#include "variables.h"
3535

36+
#ifdef MULTIBYTE
37+
#include "miscadmin.h"
38+
#include "mb/pg_wchar.h"
39+
#endif
40+
3641

3742
/* functions for use in this file */
3843

@@ -346,6 +351,30 @@ exec_command(const char *cmd,
346351
fputs("\n", fout);
347352
}
348353

354+
#ifdef MULTIBYTE
355+
/* \eset -- set client side encoding */
356+
else if (strcmp(cmd, "eset") == 0)
357+
{
358+
char *encoding = scan_option(&string, OT_NORMAL, NULL);
359+
if (PQsetClientEncoding(pset.db, encoding) == -1)
360+
{
361+
psql_error("\\%s: invalid encoding\n", cmd);
362+
}
363+
/* save encoding info into psql internal data */
364+
pset.encoding = PQclientEncoding(pset.db);
365+
free(encoding);
366+
}
367+
/* \eshow -- show encoding info */
368+
else if (strcmp(cmd, "eshow") == 0)
369+
{
370+
int encoding = PQclientEncoding(pset.db);
371+
if (encoding == -1)
372+
{
373+
psql_error("\\%s: there is no connection\n", cmd);
374+
}
375+
printf("%s\n", pg_encoding_to_char(encoding));
376+
}
377+
#endif
349378
/* \f -- change field separator */
350379
else if (strcmp(cmd, "f") == 0)
351380
{

src/bin/psql/help.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.19 2000/02/16 13:15:26 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.20 2000/02/19 05:01:16 ishii Exp $
77
*/
88
#include "postgres.h"
99
#include "help.h"
@@ -200,6 +200,10 @@ slashUsage(void)
200200
fprintf(fout, " \\dT list data types\n");
201201
fprintf(fout, " \\e [fname] edit the current query buffer or <fname> with external editor\n");
202202
fprintf(fout, " \\echo <text> write text to stdout\n");
203+
#ifdef MULTIBYTE
204+
fprintf(fout, " \\eset <encoding> set client encoding\n");
205+
fprintf(fout, " \\eshow show client encoding\n");
206+
#endif
203207
fprintf(fout, " \\g [fname] send query to backend (and results in <fname> or |pipe)\n");
204208
fprintf(fout, " \\h [cmd] help on syntax of sql commands, * for all commands\n");
205209
fprintf(fout, " \\i <fname> read and execute queries from filename\n");

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