On Fri, Dec 6, 2013 at 1:05 AM, Joe Conway <[email protected]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 12/05/2013 06:53 PM, Tom Lane wrote:
> > I seem to remember that at some point we realized that the encoding
> > ID assignments are part of libpq's ABI and so can't practically be
> > changed ever, so the above may be moot. Even so, I think it's a
> > bad idea to be depending on pg_encoding_to_char() here, given the
> > ambiguity in what it references. It would be unsurprising to get
> > build-time or run-time failures on pickier platforms, as a
> > consequence of that ambiguity. So I'd still recommend comparing
> > integer IDs as above, rather than this.
>
> Great feedback as always -- thanks! Will make that change.
>
>
Hi Joe, how are you?
Well, when Tom sent this email I was reviewing your patch and the main
suggestion is about use of 'pg_encoding_to_char' too... ;-)
The attached patch with my review!
Regards,
--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
>> Timbira: http://www.timbira.com.br
>> Blog sobre TI: http://fabriziomello.blogspot.com
>> Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
>> Twitter: http://twitter.com/fabriziomello
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index d68b12a..c358734 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -99,6 +99,7 @@ static char *generate_relation_name(Relation rel);
static void dblink_connstr_check(const char *connstr);
static void dblink_security_check(PGconn *conn, remoteConn *rconn);
static void dblink_res_error(const char *conname, PGresult *res, const char
*dblink_context_msg, bool fail);
+static void dblink_set_client_encoding(PGconn *conn);
static char *get_connect_string(const char *servername);
static char *escape_param_str(const char *from);
static void validate_pkattnums(Relation rel,
@@ -190,7 +191,7 @@ typedef struct remoteConnHashEnt
errdetail("%s",
msg))); \
} \
dblink_security_check(conn, rconn); \
- PQsetClientEncoding(conn,
GetDatabaseEncodingName()); \
+ dblink_set_client_encoding(conn); \
freeconn = true; \
} \
} while (0)
@@ -270,7 +271,7 @@ dblink_connect(PG_FUNCTION_ARGS)
dblink_security_check(conn, rconn);
/* attempt to set client encoding to match server encoding */
- PQsetClientEncoding(conn, GetDatabaseEncodingName());
+ dblink_set_client_encoding(conn);
if (connname)
{
@@ -2328,6 +2329,13 @@ dblink_res_error(const char *conname, PGresult *res,
const char *dblink_context_
dblink_context_conname,
dblink_context_msg)));
}
+static void
+dblink_set_client_encoding(PGconn *conn)
+{
+ if (PQclientEncoding(conn) != GetDatabaseEncoding())
+ PQsetClientEncoding(conn, GetDatabaseEncodingName());
+}
+
/*
* Obtain connection string for a foreign server
*/
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers