在Erlang ODBC中处理'nvarchar(MAX)`问题有什么变通办法吗?

cwdobuhd  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(163)

There seem to be some issues in Erlang ODBC relating to nvarchar(MAX) and varchar(MAX) .
For example running SELECT 'Bob' [name], 50 [age] FOR JSON PATH should give the following:

JSON_F52E2B61-18A1-11d1-B105-00805F49916B
-----------------------------------------
[{"name":"Bob","age":50}]

Erlang ODBC produces:

{:selected, ['JSON_F52E2B61-18A1-11d1-B105-00805F49916B'],
 [
   [
     <<0, 0, 80, 0, 114, 0, 111, 0, 75, 246, 34, 87, 97, 33, 0, 128, 32, 0, 70, 0, 105, 0, 108, 0, 74, 246, 33, 87, 92, 34, 0, 128, 105, 0, 99, 0, 114, 0, 111, 0, 73, 246, 32, 87, 102, 35, 0, 128, 32,
       0>>
   ]
 ]}

and on another run ...

{:selected, ['JSON_F52E2B61-18A1-11d1-B105-00805F49916B'],
 [[<<0, 0, 0, 0, 0, 0, 0, 0, 207, 63, 70, 190, 0, 5, 0, 142, 0, 0, 0, 0, 0, 0, 0, 0, 204, 63, 69, 190, 253, 6, 0, 138, 7, 0, 0, 0, 67, 0, 0, 0, 205, 63, 68, 190, 0, 7, 0, 137, 112, 97>>]]}

I'm using the following connection settings:

timeout: 30_000,
auto_commit: :on,
binary_strings: :on,
tuple_row: :off,
scrollable_cursors: :off,
trace_driver: :off,
extended_errors: :on

The output of the FOR JSON clause is of type nvarchar(MAX).
Please are there any workarounds for handling issues with nvarchar(MAX) in Erlang ODBC.

vmpqdwk3

vmpqdwk31#

有一种解决方案可以很好地在Windows上运行:通过ODBC使用OLEDB提供程序,如下所示

conn = "Provider=MSDASQL;DRIVER={SQL Server};SERVER=#{server};PORT=#{port};DATABASE=#{db};UID=#{uid};PWD=#{pwd};"

    :odbc.connect(
      to_charlist(conn),
      timeout: 30_000,
      # auto_commit: true,
      binary_strings: :on,
      tuple_row: :off,
      # scrollable_cursors: :off,
      # trace_driver: :off,
      extended_errors: :on
    )

相关问题