For a project, I do have to code a server in JS (Node) which return elements from a database (Postgres) on a Windows computer.
Everything is "working fine" in a way that connections are OK and elements are returned, however, I do have an encoding issue. My elements are in French, hence, some letters, such as "éàç", are not correctly "seen" by the server (I printed the result). The console is working with UTF8 (I tested it) so the problem is elsewhere.
It seems to me that this issue comes from the query to the database (HTML and JS from the client side are OK and support these letters). Here is a part of my code which returns the wrong things.
var client = new pg.Client({
user: 'xx',
password: 'yy',
database: 'phrases',
host: 'localhost',
client_encoding: 'utf8',
port: '5432'
});
client.connect();
client.query('SELECT id,mots from phrase WHERE langue=$1 ORDER BY anno limit 20;', ['fr'])
.then(
function(data){
text = data.rows[0].mots; //<= return the text needed
console.log(text);
}
);
I'm almost sure the problem is not from this part of code but from the database side however I may be wrong (and thus I can't see why). From the PSQL console, I do have:
show CLIENT_ENCODING; > UTF8
show SERVER_ENCODING; > UTF8
And from the database:
Nom | PropriÚtaire | Encodage | Collationnement | Type caract. | Droits d'acc
-----------+-------------+----------+----------------------------+--------------------+-----------------------
phrases | postgres | UTF8 | French_France.1252 | French_France.1252 |
I tried from a python program (print a simple request to the DB) to see if results were the same, they are; letters aren't well printed. Hence I'm sure the problem comes from the DB and are linked with the encoding but no way to find something working.
Does anyone have an idea?
Best,