diff options
author | Tatsuo Ishii <ishii@postgresql.org> | 2000-02-21 02:05:12 +0000 |
---|---|---|
committer | Tatsuo Ishii <ishii@postgresql.org> | 2000-02-21 02:05:12 +0000 |
commit | 320d3e06ee5b893c52b25ebd65a3ade4735c29e6 (patch) | |
tree | 39f4b4269904569960963c1ced27f326adb33e8a | |
parent | f72aad5678b5d9bf570a51a9899b4e950ce9f828 (diff) | |
download | postgresql-320d3e06ee5b893c52b25ebd65a3ade4735c29e6.tar.gz postgresql-320d3e06ee5b893c52b25ebd65a3ade4735c29e6.zip |
Fixes for \encoding command.
1) freeing null pointer
2) invalid encoding info may be stored into psql variable
3) fix indentation
-rw-r--r-- | src/bin/psql/command.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index c7b4577e822..07581fd82c6 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.22 2000/02/20 14:28:20 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.23 2000/02/21 02:05:12 ishii Exp $ */ #include "postgres.h" #include "command.h" @@ -354,27 +354,32 @@ exec_command(const char *cmd, fputs("\n", fout); } - /* \encoding -- set client side encoding */ + /* \encoding -- set/show client side encoding */ else if (strcmp(cmd, "encoding") == 0) { char *encoding = scan_option(&string, OT_NORMAL, NULL); - if (!encoding) - puts(pg_encoding_to_char(pset.encoding)); - else - { + if (!encoding) + /* show encoding */ + puts(pg_encoding_to_char(pset.encoding)); + else + { #ifdef MULTIBYTE - if (PQsetClientEncoding(pset.db, encoding) == -1) - psql_error("%s: invalid encoding name\n", encoding); + /* set encoding */ + if (PQsetClientEncoding(pset.db, encoding) == -1) + psql_error("%s: invalid encoding name\n", encoding); - /* save encoding info into psql internal data */ - pset.encoding = PQclientEncoding(pset.db); - SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding)); + else + { + /* save encoding info into psql internal data */ + pset.encoding = PQclientEncoding(pset.db); + SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding)); + } #else - psql_error("\\%s: multi-byte support is not enabled\n", cmd); + psql_error("\\%s: multi-byte support is not enabled\n", cmd); #endif - } - free(encoding); + free(encoding); + } } /* \f -- change field separator */ |