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.
****************************************************************************
ÿþ#include "stdafx.h"

#include <mbctype.h> // _KANJI_CP

#include <postgresql\libpq.h>



// The one and only application object



CWinApp theApp;



int test(bool bShiftJIS)

{

    wchar_t wstrText[1024];

    char strText[1024];



    // Connect

    PGconn *pConn = PQsetdbLogin(NULL, 
NULL, NULL, NULL, "DEV308", "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 ÛV—[(gid serial PRIMARY 
KEY,¬Šf text,¢0¤0Æ0à0id integer,¢0¤0Æ0à0¯0é0¹0 
text,ŸS¹px double precision,ŸS¹py double 
precision,ŸS¹pz 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 ÛV—[";

    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'ŸS') {

                
::printf("PQfname(pResult, %d) returned 
incorrect field name.\n", i);

            }

        }

    }



    PQclear(pResult);



    // Drop table

    const wchar_t wstrCommand3[] = 
L"drop table ÛV—[";

    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