pramsey / pgsql-ogr-fdw

PostgreSQL foreign data wrapper for OGR
MIT License
237 stars 34 forks source link

Add 'character_encoding' server option #197

Closed pramsey closed 3 years ago

pramsey commented 3 years ago

Allows users to set the assumed server encoding, when they know it, so OGR FDW can transcode the strings on input. Can be tricky for some drivers: for example, the PgSQL client driver automatically sets the client encoding to UTF-8, which when used against a SQL_ASCII database results in a transcoding failure before the data can even reach the FDW. This should address #193.

bowguy commented 3 years ago

Let me see if I can test it this afternoon

bowguy commented 3 years ago

running make:

ogr_fdw_info.c:31:1: error: static declaration of 'strupr' follows non-static declaration 31 | strupr(char str) | ^~ In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/io.h:10, from C:/msys64/mingw64/x86_64-w64-mingw32/include/unistd.h:10, from ogr_fdw_info.c:16: C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:125:17: note: previous declaration of 'strupr' was here 125 | char __cdecl strupr(char *_Str) __MINGW_ATTRIB_DEPRECATED_MSVC2005; | ^~ make: *** [: ogr_fdw_info.o] Error 1

bowguy commented 3 years ago

testing

  1. No configuration options: 'utf-8' codec can't decode byte 0xbe in position 4: invalid start byte
  2. character_encoding 'WIN1250' "4X4 ľTON P/U"
  3. character_encoding 'LATIN1' "4X4 ¾TON P/U"

This looks like it is working perfectly!!

Note ogr-fdw-info gives:

CREATE SERVER myserver FOREIGN DATA WRAPPER ogr_fdw OPTIONS ( datasource 'ODBC:foo@bar', format 'ODBC', config_options '');

Note Readme.md only talks about character_encoding options, not config_options.

Above tests were on PG12, GDAL 2.4.4 I'll try to test on PG13 ASAP

Thanks!!