Hi Martin-san.

Probably it is not a bug.
Does this help you?
Please see.

C:\home\HIROSHI>cl TestPostgreSQLJapanese.cpp -I"C:\Program Files\PostgreSQL\8.4
\include" "C:\Program Files\PostgreSQL\8.4\lib\libpq.lib"
Microsoft(R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

TestPostgreSQLJapanese.cpp
WINVER not defined. Defaulting to 0x0600 (Windows Vista)
c:\Program Files\Microsoft Visual Studio 9.0\VC\ATLMFC\INCLUDE\afxwin1.inl(105)
: warning C4530: C++ 例外処理を使っていますが、アンワインド セマンティクスは有効
にはなりません。/EHsc を指定してください。
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:TestPostgreSQLJapanese.exe
TestPostgreSQLJapanese.obj
"C:\Program Files\PostgreSQL\8.4\lib\libpq.lib"

C:\home\HIROSHI>set Path=%Path%;C:\Program Files\PostgreSQL\8.4\bin;

C:\home\HIROSHI>TestPostgreSQLJapanese.exe
Testing with encoding UTF-8:
NOTICE:  CREATE TABLE will create implicit sequence "蝗帛ョ誉gid_seq" for serial
column "蝗帛ョ・gid"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "蝗帛ョ誉pkey" for
table "蝗帛ョ・

Testing with encoding SJIS:
NOTICE:  CREATE TABLE will create implicit sequence "四宗_gid_seq" for serial co
lumn "四宗.gid"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "四宗_pkey" for t
able "四宗"

Press any key to exit.


Regards,
Hiroshi Saito

----- Original Message ----- From: "Martin Schäfer" <martin.schae...@cadcorp.com>
To: <pgsql-bugs@postgresql.org>
Sent: Thursday, March 25, 2010 8:27 PM
Subject: [BUGS] UTF-8 encoding failure


Hi,

Is this the right place to report bugs?

The attached program creates a table with Japanese column names. When the column names are retrieved in a query using PQfname, and invalid string is returned. The invalid column names can also be seen in PGAdmin III. This only seems to happen with one (or more?) specific Japanese character.

Operating System: Windows Vista Ultimate SP2 32bit
PostgreSQL server versions: 8.4.2 and 8.3.3 both fail
libpq version: 8.3.6
Database encoding: UTF8
Client encoding:
- UTF8: does not return the same column name used to create the table.
- SJIS: "select * from table" fails with error:
   ERROR:  invalid byte sequence for encoding "UTF8": 0xe59eff
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

From what I can see the character in question has the following encodings:
SJIS:     8c b4
UTF-16:     9f 53
UTF-8:     e5 8e 9f

Any chance this problem could be fixed soon?

Bye,

Martin Schäfer
Principal Software Engineer
Cadcorp
Computer Aided Development Corporation Ltd.
1 Heathcock Court, London, WC2R 0NT
martin.schae...@cadcorp.com
www.cadcorp.com
****************************************************************************
This email is confidential and may be privileged and should not be used, read
or copied by anyone who is not the  original intended recipient. If you have
received this email in error  please inform the sender and delete it from
your mailbox or any other storage mechanism. Unless specifically stated,
nothing in this email constitutes an offer by Cadcorp and Cadcorp does not
warrant that any information contained in this email is accurate.
Cadcorp cannot accept liability for any statements made which are clearly the
sender's own and not expressly made on behalf of Cadcorp or one of its agents.
Please rely on your own virus check. No responsibility is taken by Cadcorp
for any damage arising out of any bug or virus infection.
****************************************************************************



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



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

#include <afxwin.h>
#include <mbctype.h> // _KANJI_CP
#include <libpq-fe.h>

// The one and only application object

CWinApp theApp;

int test(bool bShiftJIS)
{
   wchar_t wstrText[1024];
   char strText[1024];

   // Connect
   PGconn *pConn = PQsetdbLogin("localhost", "5433", NULL, NULL, "postgres", "postgres", 
"postgres");
   if (!pConn) return __LINE__;
   if (PQstatus(pConn) != CONNECTION_OK) return __LINE__;

   // Set Client encoding
   UINT codepage;
   if (bShiftJIS) {
       if (PQsetClientEncoding(pConn, "SJIS") != 0) return __LINE__;
       codepage = _KANJI_CP;
   } else {
       if (PQsetClientEncoding(pConn, "UTF-8") != 0) return __LINE__;
       codepage = CP_UTF8;
   }

   // Create table
   const wchar_t wstrCommand[] = L"create table Žl@(gid serial PRIMARY KEY,à–¾ 
text,ƒAƒCƒeƒ€id integer,ƒAƒCƒeƒ€ƒNƒ‰ƒX text,Œ´“_x double precision,Œ´“_y double 
precision,Œ´“_z double precision)";
   if (::WideCharToMultiByte(codepage, 0, wstrCommand, -1, strText, 
_countof(strText), NULL, NULL) == 0) return __LINE__;

   PGresult *pResult = PQexec(pConn, strText);
   if (!pResult) return __LINE__;
   int stat = PQresultStatus(pResult);
   if (stat != PGRES_EMPTY_QUERY && stat != PGRES_COMMAND_OK && stat != 
PGRES_TUPLES_OK) return __LINE__;

   PQclear(pResult);

   // Query table
   const wchar_t wstrCommand2[] = L"select * from Žl@";
   if (::WideCharToMultiByte(codepage, 0, wstrCommand2, -1, strText, 
_countof(strText), NULL, NULL) == 0) return __LINE__;

   pResult = PQexec(pConn, strText);
   if (!pResult) return __LINE__;
   stat = PQresultStatus(pResult);
   if (stat != PGRES_EMPTY_QUERY && stat != PGRES_COMMAND_OK && stat != 
PGRES_TUPLES_OK) {
       if (::MultiByteToWideChar(codepage, 0, PQresultErrorMessage(pResult), 
-1, wstrText, _countof(wstrText)) == 0) return __LINE__;
       ::wprintf(L"Query failed with error:\n%s\n", wstrText);
   } else {
       for (int i = 4; i < PQnfields(pResult); ++i) {
           const char *strFieldName = PQfname(pResult, i);
           if (::MultiByteToWideChar(codepage, 0, strFieldName, -1, wstrText, 
_countof(wstrText)) == 0) return __LINE__;
           //::wprintf(L"Field name %d is %s\n", i + 1, wstrText);
           if (wstrText[0] != L'Ϋ') {
               ::printf("PQfname(pResult, %d) returned incorrect field 
name.\n", i);
           }
       }
   }

   PQclear(pResult);

   // Drop table
   const wchar_t wstrCommand3[] = L"drop table Žl@";
   if (::WideCharToMultiByte(codepage, 0, wstrCommand3, -1, strText, 
_countof(strText), NULL, NULL) == 0) return __LINE__;

   pResult = PQexec(pConn, strText);
   PQclear(pResult);

   PQfinish(pConn);
   return 0;
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
        int nRetCode = 0;

        // initialize MFC and print and error on failure
        if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        {
                // TODO: change error code to suit your needs
                _tprintf(_T("Fatal Error: MFC initialization failed\n"));
                nRetCode = 1;
        }
        else
        {
                // TODO: code your application's behavior here.
                int rv;
                ::printf("Testing with encoding UTF-8:\n");
                rv = test(false);
                if (rv) ::printf("Test failed on line %d.\n", rv);

                ::printf("\nTesting with encoding SJIS:\n");
                rv = test(true);
                if (rv) ::printf("Test failed on line %d.\n", rv);
        }

   ::printf("\nPress any key to exit.\n");
   getchar();
        return nRetCode;
}
-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to