33 *
44 * Copyright (c) 2000-2003, PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.73 2003/09/03 22:05:08 petere Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.74 2003/09/16 17:59:02 tgl Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
3333#include "prompt.h"
3434#include "print.h"
3535#include "mainloop.h"
36+ #include "mb/pg_wchar.h"
3637
3738
3839/* Workarounds for Windows */
@@ -360,6 +361,9 @@ AcceptResult(const PGresult *result)
360361 * In autocommit-off mode, a new transaction block is started if start_xact
361362 * is true; nothing special is done when start_xact is false. Typically,
362363 * start_xact = false is used for SELECTs and explicit BEGIN/COMMIT commands.
364+ *
365+ * Note: we don't bother to check PQclientEncoding; it is assumed that no
366+ * caller uses this path to issue "SET CLIENT_ENCODING".
363367 */
364368PGresult *
365369PSQLexec (const char * query , bool start_xact )
@@ -416,7 +420,6 @@ PSQLexec(const char *query, bool start_xact)
416420
417421/*
418422 * PrintNotifications: check for asynchronous notifications, and print them out
419- *
420423 */
421424static void
422425PrintNotifications (void )
@@ -427,8 +430,8 @@ PrintNotifications(void)
427430 {
428431 fprintf (pset .queryFout , gettext ("Asynchronous notification \"%s\" received from server process with PID %d.\n" ),
429432 notify -> relname , notify -> be_pid );
430- PQfreemem (notify );
431433 fflush (pset .queryFout );
434+ PQfreemem (notify );
432435 }
433436}
434437
@@ -625,7 +628,20 @@ SendQuery(const char *query)
625628 OK = (AcceptResult (results ) && PrintQueryResults (results , & before , & after ));
626629 PQclear (results );
627630
631+ /* check for events that may occur during query execution */
632+
633+ if (pset .encoding != PQclientEncoding (pset .db ) &&
634+ PQclientEncoding (pset .db ) >= 0 )
635+ {
636+ /* track effects of SET CLIENT_ENCODING */
637+ pset .encoding = PQclientEncoding (pset .db );
638+ pset .popt .topt .encoding = pset .encoding ;
639+ SetVariable (pset .vars , "ENCODING" ,
640+ pg_encoding_to_char (pset .encoding ));
641+ }
642+
628643 PrintNotifications ();
644+
629645 return OK ;
630646}
631647
0 commit comments