What i'am trying: - just make a select with erlang-odbc from elixir and dump all result to console.
Enviroment: my side
- Red Hat Enterprise Linux Server release 7.6 (Maipo)
- unixODBC-devel ( yum)
- Elixir 1.8.2 (compiled with Erlang/OTP 20)
- Erlang/OTP 21
- erlang-odbc R16B (yum)
- (either) mssql driver
- (or) FreeTds driver 1.1.6 (compiled from sources --with-unixodbc)
target
- mssql server 2016
- table
CREATE TABLE db_name.dbo.rating (
[Year] int NULL,
Code varchar(256) COLLATE Cyrillic_General_CI_AS NULL,
Name nvarchar(4000) COLLATE Cyrillic_General_CI_AS NULL,
GroupeCode varchar(256) COLLATE Cyrillic_General_CI_AS NULL,
GroupeName nvarchar(4000) COLLATE Cyrillic_General_CI_AS NULL,
Cost numeric(38,5) NOT NULL,
PrchasesCount int NULL
) GO
nvarchar: character_set_name: UNICODE collation_name: Cyrillic_General_CI_AS
varchar: character_set_name: cp1251 collation_name: Cyrillic_General_CI_AS
elixir code looks like:
conn_str =
"SERVER=XX.XX.XX.XX,1433;" <>
#tried this too! "DRIVER={ODBC Driver 17 for SQL Server};" <>
"DRIVER=FreeTDS;" <>
"DATABASE=db_name;UID=bot;PWD=XXXXXX;"
|> to_charlist
statement = "select top(3) Name from Rating order by Cost desc" |> to_charlist
{:ok, pid}=:odbc.connect(conn_str,[])
{:selected, col_names, rows} = :odbc.sql_query(pid, statement)
and, after all attempts, i have something like this in result
{:selected, ['Name'],
[
{<<32, 4, 48, 4, 49, 4, 62, 4, 66, 4, 75, 4, 32, 0, 65, 4, 66, 4, 64, 4, 62,
4, 56, 4, 66, 4, 53, 4, 59, 4, 76, 4, 61, 4, 75, 4, 53, 4, 32, 0, 63, 4,
62, 4, 32, ...>>},
{<<16, 4, 64, 4, 53, 4, 61, 4, 52, 4, 48, 4, 32, 0, 63, 4, 48, 4, 65, 4, 65,
4, 48, 4, 54, 4, 56, 4, 64, 4, 65, 4, 58, 4, 62, 4, 51, 4, 62, 4, 32, 0,
66, 4, ...>>},
{<<35, 4, 65, 4, 59, 4, 67, 4, 51, 4, 56, 4, 32, 0, 63, 4, 62, 4, 32, 0, 64,
4, 53, 4, 58, 4, 67, 4, 59, 4, 76, 4, 66, 4, 56, 4, 50, 4, 48, 4, 70, 4,
56, ...>>}
]}
instead a correct Cyrillic text
its a not random numbers! result always the same.
MS driver gives same result as FreeTDS
what else i've tried
- changing conn options binary_strings: :on/off
- setting option client charset = UTF-8 in freetds.conf (in global section)
- scratching my head
- using :unicode functions to read << data >>
- using is_binary() on received numbers returns true
Questions
- what type of data do i receive?
- why data is not correct decoded?
- what app is responsible for it?
- how can i fix it? some part of freetds log here (about iconv)
iconv.c:326:tds_iconv_open(0x1e02330, UTF-8)
iconv.c:186:local name for ISO-8859-1 is ISO-8859-1
iconv.c:186:local name for UTF-8 is UTF-8
iconv.c:186:local name for UCS-2LE is UCS-2LE
iconv.c:186:local name for UCS-2BE is UCS-2BE
iconv.c:348:setting up conversions for client charset "UTF-8"
iconv.c:350:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:389:tds_iconv_open: done
iconv.c:785:setting server single-byte charset to "CP1251"