I'm trying to access data that is stored in a MSSQL spatial database and it seems to me that OGR is having some problems with accents. I'm not sure if maybe there is an encoding parameter or something else I could try before I report an issue on github.
Under Windows 10 and chcp 1252, using this command ogrinfo --debug on MSSQL:"server=server;database=db;trusted_connection=yes;tables=schema.table" -sql "select distinct categorie from schema.table", all distinct values are returned as expected. Among these are a couple that contain french accents:
OGRFeature(SELECT):4
categorie (String) = Véhicule électrique en recharge
OGRFeature(SELECT):5
categorie (String) = Véhicule électrique
OGRFeature(SELECT):6
categorie (String) = Régulier
OGRFeature(SELECT):8
categorie (String) = Réservé véhicule électrique
If I add this to the SQL query in the original command where categorie in ('Véhicule électrique en recharge', 'Véhicule électrique', 'Réservé véhicule électrique'), then OGR returns a Feature Count: 0 because the accents are not sent properly: MSSQLSpatial: ExecuteSQL(select distinct categorie from schema.table where categorie in ('Véhicule électrique en recharge', 'Véhicule électrique', 'Réservé véhicule électrique')) called.
If I change chcp to 65001, then the accents are sent properly MSSQLSpatial: ExecuteSQL(select distinct categorie from schema.table where categorie in ('Véhicule électrique en recharge', 'Véhicule électrique', 'Réservé véhicule électrique')) called., yet I still get a Feature Count: 0.
So with chcp still to 65001, I execute the original command again (only select distinct categorie) and then I get:
OGRFeature(SELECT):4
categorie (String) = Vhicule lectrique en recharge
OGRFeature(SELECT):5
categorie (String) = Vhicule lectrique
OGRFeature(SELECT):6
categorie (String) = Rgulier
OGRFeature(SELECT):8
categorie (String) = Rserv vhicule lectrique
The "é" character is simply removed.
I can bypass this problem in both chcp by using where categorie like '%lectrique%', but I'd like to know if there is some way to send my query with accents and values with accents are returned.
-sql @stored_sql.txt. I have not tried that myself, just thinking that it could work. – user30184 Mar 06 '23 at 21:39