3
3
*
4
4
* Copyright 2000 by PostgreSQL Global Development Group
5
5
*
6
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.21 2000/02/2002:37:40 tgl Exp $
6
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.22 2000/02/2014:28:20 petere Exp $
7
7
*/
8
8
#include "postgres.h"
9
9
#include "command.h"
36
36
#ifdef MULTIBYTE
37
37
#include "miscadmin.h"
38
38
#include "mb/pg_wchar.h"
39
+ #else
40
+ /* Grand unified hard-coded badness */
41
+ #define pg_encoding_to_char (x ) "SQL_ASCII"
39
42
#endif
40
43
41
44
@@ -351,30 +354,29 @@ exec_command(const char *cmd,
351
354
fputs ("\n" ,fout );
352
355
}
353
356
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 )
357
359
{
358
360
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 );
377
375
#endif
376
+ }
377
+ free (encoding );
378
+ }
379
+
378
380
/* \f -- change field separator */
379
381
else if (strcmp (cmd ,"f" )== 0 )
380
382
{
@@ -425,7 +427,7 @@ exec_command(const char *cmd,
425
427
}
426
428
else
427
429
{
428
- success = process_file (fname );
430
+ success = process_file (fname )== EXIT_SUCCESS ;
429
431
free (fname );
430
432
}
431
433
}
@@ -1148,6 +1150,7 @@ do_connect(const char *new_dbname, const char *new_user)
1148
1150
SetVariable (pset .vars ,"USER" ,NULL );
1149
1151
SetVariable (pset .vars ,"HOST" ,NULL );
1150
1152
SetVariable (pset .vars ,"PORT" ,NULL );
1153
+ SetVariable (pset .vars ,"ENCODING" ,NULL );
1151
1154
1152
1155
/* If dbname is "" then use old name, else new one (even if NULL) */
1153
1156
if (oldconn && new_dbname && PQdb (oldconn )&& strcmp (new_dbname ,"" )== 0 )
@@ -1247,6 +1250,7 @@ do_connect(const char *new_dbname, const char *new_user)
1247
1250
SetVariable (pset .vars ,"USER" ,PQuser (pset .db ));
1248
1251
SetVariable (pset .vars ,"HOST" ,PQhost (pset .db ));
1249
1252
SetVariable (pset .vars ,"PORT" ,PQport (pset .db ));
1253
+ SetVariable (pset .vars ,"ENCODING" ,pg_encoding_to_char (pset .encoding ));
1250
1254
1251
1255
pset .issuper = test_superuser (PQuser (pset .db ));
1252
1256
@@ -1471,7 +1475,7 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
1471
1475
* Read commands from filename and then them to the main processing loop
1472
1476
* Handler for \i, but can be used for other things as well.
1473
1477
*/
1474
- bool
1478
+ int
1475
1479
process_file (char * filename )
1476
1480
{
1477
1481
FILE * fd ;
@@ -1494,7 +1498,7 @@ process_file(char *filename)
1494
1498
result = MainLoop (fd );
1495
1499
fclose (fd );
1496
1500
pset .inputfile = oldfilename ;
1497
- return ( result == EXIT_SUCCESS ) ;
1501
+ return result ;
1498
1502
}
1499
1503
1500
1504