33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.21 2000/02/20 02:37:40 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.22 2000/02/20 14:28:20 petere Exp $
77 */
88#include "postgres.h"
99#include "command.h"
3636#ifdef MULTIBYTE
3737#include "miscadmin.h"
3838#include "mb/pg_wchar.h"
39+ #else
40+ /* Grand unified hard-coded badness */
41+ #define pg_encoding_to_char (x ) "SQL_ASCII"
3942#endif
4043
4144
@@ -351,30 +354,29 @@ exec_command(const char *cmd,
351354 fputs ("\n" , fout );
352355 }
353356
354- #ifdef MULTIBYTE
355- /* \eset -- set client side encoding */
356- else if (strcmp (cmd , "eset ") == 0 )
357+ /* \encoding -- set client side encoding */
358+ else if (strcmp (cmd , "encoding" ) == 0 )
357359 {
358360 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- }
361+
362+ if (!encoding )
363+ puts (pg_encoding_to_char (pset .encoding ));
364+ else
365+ {
366+ #ifdef MULTIBYTE
367+ if (PQsetClientEncoding (pset .db , encoding ) == -1 )
368+ psql_error ("%s: invalid encoding name\n" , encoding );
369+
370+ /* save encoding info into psql internal data */
371+ pset .encoding = PQclientEncoding (pset .db );
372+ SetVariable (pset .vars , "ENCODING" , pg_encoding_to_char (pset .encoding ));
373+ #else
374+ psql_error ("\\%s: multi-byte support is not enabled\n" , cmd );
377375#endif
376+ }
377+ free (encoding );
378+ }
379+
378380 /* \f -- change field separator */
379381 else if (strcmp (cmd , "f" ) == 0 )
380382 {
@@ -425,7 +427,7 @@ exec_command(const char *cmd,
425427 }
426428 else
427429 {
428- success = process_file (fname );
430+ success = process_file (fname ) == EXIT_SUCCESS ;
429431 free (fname );
430432 }
431433 }
@@ -1148,6 +1150,7 @@ do_connect(const char *new_dbname, const char *new_user)
11481150 SetVariable (pset .vars , "USER" , NULL );
11491151 SetVariable (pset .vars , "HOST" , NULL );
11501152 SetVariable (pset .vars , "PORT" , NULL );
1153+ SetVariable (pset .vars , "ENCODING" , NULL );
11511154
11521155 /* If dbname is "" then use old name, else new one (even if NULL) */
11531156 if (oldconn && new_dbname && PQdb (oldconn ) && strcmp (new_dbname , "" ) == 0 )
@@ -1247,6 +1250,7 @@ do_connect(const char *new_dbname, const char *new_user)
12471250 SetVariable (pset .vars , "USER" , PQuser (pset .db ));
12481251 SetVariable (pset .vars , "HOST" , PQhost (pset .db ));
12491252 SetVariable (pset .vars , "PORT" , PQport (pset .db ));
1253+ SetVariable (pset .vars , "ENCODING" , pg_encoding_to_char (pset .encoding ));
12501254
12511255 pset .issuper = test_superuser (PQuser (pset .db ));
12521256
@@ -1471,7 +1475,7 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
14711475 * Read commands from filename and then them to the main processing loop
14721476 * Handler for \i, but can be used for other things as well.
14731477 */
1474- bool
1478+ int
14751479process_file (char * filename )
14761480{
14771481 FILE * fd ;
@@ -1494,7 +1498,7 @@ process_file(char *filename)
14941498 result = MainLoop (fd );
14951499 fclose (fd );
14961500 pset .inputfile = oldfilename ;
1497- return ( result == EXIT_SUCCESS ) ;
1501+ return result ;
14981502}
14991503
15001504
0 commit comments