pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Igor Korot <ikorot01@gmail.com>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Error on Windows
Date: Thu, 10 Jan 2019 15:44:11 +0100
Message-ID: <2b03726068c6c4f20b41230c3025a52e8bcdffad.camel@cybertec.at> (raw)
In-Reply-To: <CA+FnnTzTD2dy7qnMXo=QJYi2i9a=B=_DFa65b98LfR4ZMTpH=A@mail.gmail.com>
References: <CA+FnnTzTD2dy7qnMXo=QJYi2i9a=B=_DFa65b98LfR4ZMTpH=A@mail.gmail.com>

Igor Korot wrote:
> The following code compiles and executes but returns an error:
> 
> [quote]
> Invalid byte sequence for encoding UTF8
> [/quote]
> 
> [code]
>     char *values[2];
>     values[0] = NULL, values[1] = NULL;
>     values[0] = new char[schemaName.length() + 1];
>     values[1] = new char[tableName.length() + 1];
>     memset( values[0], '\0', schemaName.length() + 1 );
>     memset( values[1], '\0', tableName.length() + 1 );
>     strcpy( values[0], m_pimpl->m_myconv.to_bytes( schemaName.c_str()
> ).c_str() );
>     strcpy( values[1], m_pimpl->m_myconv.to_bytes( tableName.c_str()
> ).c_str() );
>     int len1 = (int) schemaName.length();
>     int len2 = (int) tableName.length();
>     int length[2] = { len1, len2 };
>     int formats[2] = { 1, 1 };
>     PGresult *res = PQexecParams( m_db, m_pimpl->m_myconv.to_bytes(
> query.c_str() ).c_str(), 2, NULL, values, length, formats, 1 );
>     ExecStatusType status = PQresultStatus( res );
>     if( status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK )
>     {
>         result = 1;
>         std::wstring err = m_pimpl->m_myconv.from_bytes(
> PQerrorMessage( m_db ) );
>         errorMsg.push_back( L"Error executing query: " + err );
>         PQclear( res );
>     }
> [/code]
> 
> in the "err" variable.
> 
> Looking under MSVC debugger I see for a tableName a following sequence:
> 
> 97 98 99 223
> 
> What can I do to eliminate the error?

I'd say you should set the client encoding correctly.

Looks like the bytes represent "abcß" in some LATIN-? encoding.

Yours,
Laurenz Albe

-- 
Cybertec | https://www.cybertec-postgresql.com





view thread (2+ messages)

Message-ID: <2b03726068c6c4f20b41230c3025a52e8bcdffad.camel@cybertec.at>
Permalink:  ../2b03726068c6c4f20b41230c3025a52e8bcdffad.camel@cybertec.at/
Also on:    postgresql.org/message-id/2b03726068c6c4f20b41230c3025a52e8bcdffad.camel@cybertec.at

 · 

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-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, ikorot01@gmail.com
  Subject: Re: Error on Windows
  In-Reply-To: <2b03726068c6c4f20b41230c3025a52e8bcdffad.camel@cybertec.at>
  References: <CA+FnnTzTD2dy7qnMXo=QJYi2i9a=B=_DFa65b98LfR4ZMTpH=A@mail.gmail.com> <2b03726068c6c4f20b41230c3025a52e8bcdffad.camel@cybertec.at>

* 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