Fixes for \encoding command.
1) freeing null pointer 2) invalid encoding info may be stored into psql variable 3) fix indentation
This commit is contained in:
parent
f72aad5678
commit
320d3e06ee
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* 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 "postgres.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -354,27 +354,32 @@ exec_command(const char *cmd,
|
|||||||
fputs("\n", fout);
|
fputs("\n", fout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \encoding -- set client side encoding */
|
/* \encoding -- set/show client side encoding */
|
||||||
else if (strcmp(cmd, "encoding") == 0)
|
else if (strcmp(cmd, "encoding") == 0)
|
||||||
{
|
{
|
||||||
char *encoding = scan_option(&string, OT_NORMAL, NULL);
|
char *encoding = scan_option(&string, OT_NORMAL, NULL);
|
||||||
|
|
||||||
if (!encoding)
|
if (!encoding)
|
||||||
puts(pg_encoding_to_char(pset.encoding));
|
/* show encoding */
|
||||||
else
|
puts(pg_encoding_to_char(pset.encoding));
|
||||||
{
|
else
|
||||||
|
{
|
||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
if (PQsetClientEncoding(pset.db, encoding) == -1)
|
/* set encoding */
|
||||||
psql_error("%s: invalid encoding name\n", encoding);
|
if (PQsetClientEncoding(pset.db, encoding) == -1)
|
||||||
|
psql_error("%s: invalid encoding name\n", encoding);
|
||||||
|
|
||||||
/* save encoding info into psql internal data */
|
else
|
||||||
pset.encoding = PQclientEncoding(pset.db);
|
{
|
||||||
SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
|
/* save encoding info into psql internal data */
|
||||||
|
pset.encoding = PQclientEncoding(pset.db);
|
||||||
|
SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
psql_error("\\%s: multi-byte support is not enabled\n", cmd);
|
psql_error("\\%s: multi-byte support is not enabled\n", cmd);
|
||||||
#endif
|
#endif
|
||||||
}
|
free(encoding);
|
||||||
free(encoding);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \f -- change field separator */
|
/* \f -- change field separator */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user