From 7525072cf0d1923c030e804b3a5bdabab42a9ed6 Mon Sep 17 00:00:00 2001 From: "Stephen R. van den Berg" <srb@cuci.nl> Date: Thu, 28 May 2020 20:51:46 +0200 Subject: [PATCH] pgsql: Autoconvert to UTF-8 for types as CITEXT. --- lib/modules/Sql.pmod/pgsql_util.pmod | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod index 52d946e265..9bf23ab616 100644 --- a/lib/modules/Sql.pmod/pgsql_util.pmod +++ b/lib/modules/Sql.pmod/pgsql_util.pmod @@ -1233,7 +1233,7 @@ class sql_result { plugbuffer->add_int32(-1); break; } - if (!objectp(value) || typeof(value) != typeof(Stdio.Buffer())); + if (!objectp(value) || typeof(value) != typeof(Stdio.Buffer())) /* * Like Oracle and SQLite, we accept literal binary values * from single-valued multisets. @@ -1242,20 +1242,20 @@ class sql_result { value = indices(value)[0]; else { value = (string)value; - if (String.width(value) > 8) - if (dtoid[i] == BYTEAOID) + if (cenc == UTF8CHARSET + && (dtoid[i] != BYTEAOID || String.width(value) > 8)) /* - * FIXME We should throw an error here, it would - * have been correct, but for historical reasons and - * as a DWIM convenience we autoconvert to UTF8 here. + * FIXME For BYTEAOID and wide strings we should + * throw an error here, but for historical reasons and + * as a DWIM convenience we autoconvert to UTF8 anyway. */ - value = string_to_utf8(value); - else { - SUSERERROR( - "Wide string %O not supported for type OID %d\n", - value, dtoid[i]); - value = ""; - } + value = string_to_utf8(value); + else if (String.width(value) > 8) { + SUSERERROR( + "Wide string %O not supported for type OID %d\n", + value, dtoid[i]); + value = ""; + } } plugbuffer->add_hstring(value, 4); break; -- GitLab