pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: martin.schaefer@cadcorp.com
To: pgsql-bugs@postgresql.org
Subject: BUG #8210: UTF8 column names corrupted by server
Date: Wed, 05 Jun 2013 06:54:29 +0000
Message-ID: <E1Uk7c5-0001IJ-KP@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      8210
Logged by:          Martin Schaefer
Email address:      martin.schaefer@cadcorp.com
PostgreSQL version: 9.2.1
Operating system:   Windows 8
Description:        

The following code:

    const wchar_t *strName = L"id_äß";
    wstring strCreate = wstring(L"create table test_umlaut(") + strName + L"
integer primary key)";

    PGconn *pConn = PQsetdbLogin("", "", NULL, NULL, "dev503", "postgres",
"******");
    if (!pConn) FAIL;
    if (PQsetClientEncoding(pConn, "UTF-8")) FAIL;

    PGresult *pResult = PQexec(pConn, "drop table test_umlaut");
    if (pResult) PQclear(pResult);

    pResult = PQexec(pConn, ToUtf8(strCreate.c_str()).c_str());
    if (pResult) PQclear(pResult);

    pResult = PQexec(pConn, "select * from test_umlaut");
    if (!pResult) FAIL;
    if (PQresultStatus(pResult)!=PGRES_TUPLES_OK) FAIL;
    if (PQnfields(pResult)!=1) FAIL;
    const char *fName = PQfname(pResult,0);

    ShowW("Name:     ", strName);
    ShowA("in UTF8:  ", ToUtf8(strName).c_str());
    ShowA("from DB:  ", fName);
    ShowW("in UTF16: ", ToWide(fName).c_str());

    PQclear(pResult);
    PQreset(pConn);

(ShowA/W call OutputDebugStringA/W, and ToUtf8/ToWide use
WideCharToMultiByte/MultiByteToWideChar with CP_UTF8.)

generates this output:

Name:     id_äß
in UTF8:  id_äß
from DB:  id_ã¤ãÿ
in UTF16: id_???

The back-end treats the name as if it were in ANSI encoding, not in UTF-8,
when it lower-cases the name. The resulting column name is corrupted.

I’m using PostgreSQL 9.2.1, compiled by Visual C++ build 1600, 64-bit

The database uses:
ENCODING = 'UTF8'
LC_COLLATE = 'English_United Kingdom.1252'
LC_CTYPE = 'English_United Kingdom.1252'




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



Message-ID: <E1Uk7c5-0001IJ-KP@wrigleys.postgresql.org>
Permalink:  ../E1Uk7c5-0001IJ-KP@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1Uk7c5-0001IJ-KP@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: martin.schaefer@cadcorp.com
  Subject: Re: BUG #8210: UTF8 column names corrupted by server
  In-Reply-To: <E1Uk7c5-0001IJ-KP@wrigleys.postgresql.org>
  References: <E1Uk7c5-0001IJ-KP@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox