Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
How handle UTF-8 encoding error in libpq?

I have created this function to insert data into database:

void add_data_to_db(){
        const char *data[2][2] = {"2","e"};
        re = PQexecParams(connection,
                        "INSERT INTO test_table "\
                        "VALUES ($1, $2);",
                        2,NULL,data[2],NULL,NULL,0);
        if(PQresultStatus(re) != PGRES_TUPLES_OK){
                printf("%s\n", PQresultErrorMessage(re));
        }

        PQclear(re);
}

but when I run the program it prints :

ERROR:  invalid byte sequence for encoding "UTF8": 0x80

as far as I know this problem occurs when we have null value adding to table but I have not.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

According to the documentation the fifth argument of PQExecParams should be const char * const *paramValues ... so a pointer to constant pointers which point to constant char. The documentation specifies that it should point to an array of the specified (in the third argument) length (2 here).

data[2] is the third element of the data array (whoops, it has only two elements!).

data would decay to a pointer to the first element; that is a pointer to an array of two pointers which each point to a string. Exactly what you need.

over 4 years ago · Santiago Trujillo Relatório

0

It should be const char *data[2], and the function call should have data rather than data[2].

The error message means that PostgreSQL encountered bytes that are not part of a correctly encoded UTF-8 string.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda