Default client encoding to server encoding for dblink connections. Addresses
authorJoe Conway <mail@joeconway.com>
Tue, 9 Jun 2009 16:35:36 +0000 (16:35 +0000)
committerJoe Conway <mail@joeconway.com>
Tue, 9 Jun 2009 16:35:36 +0000 (16:35 +0000)
issue raised by Ruzsinszky Attila and confirmed by others.

 ----------------------------------------------------------------------

contrib/dblink/dblink.c

index c06413d5a45e745568285daac6e29664627a1d57..dd35feef5d73fc9f1597a71402d733a6d08f5cb5 100644 (file)
@@ -48,6 +48,7 @@
 #include "executor/spi.h"
 #include "foreign/foreign.h"
 #include "lib/stringinfo.h"
+#include "mb/pg_wchar.h"
 #include "miscadmin.h"
 #include "nodes/execnodes.h"
 #include "nodes/nodes.h"
@@ -185,6 +186,7 @@ typedef struct remoteConnHashEnt
                                                         errdetail("%s", msg))); \
                                } \
                                dblink_security_check(conn, rconn); \
+                               PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
                                freeconn = true; \
                        } \
        } while (0)
@@ -263,6 +265,9 @@ dblink_connect(PG_FUNCTION_ARGS)
        /* check password actually used if not superuser */
        dblink_security_check(conn, rconn);
 
+       /* attempt to set client encoding to match server encoding */
+       PQsetClientEncoding(conn, GetDatabaseEncodingName());
+
        if (connname)
        {
                rconn->conn = conn;