Packages
tds
1.0.12
2.3.8
2.3.7
2.3.6
2.3.5
2.3.4
2.3.2
2.3.1
2.3.0
2.3.0-rc.1
2.3.0-rc.0
2.2.0
2.1.3
2.1.2
2.1.1
2.1.0
2.0.4
2.0.3
2.0.2
2.0.1
2.0.1-rc2
2.0.1-rc1
2.0.0
retired
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.0
1.0.19
1.0.18
1.0.17
1.0.16
1.0.15
1.0.14
1.0.13
1.0.12
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Microsoft SQL Server client (Elixir implementation of the MS TDS protocol)
Current section
Files
Jump to
Current section
Files
lib/tds/utils.ex
defmodule Tds.Utils do
@moduledoc false
require Logger
def to_hex_list(x) when is_list(x) do
Enum.map(x, &Base.encode16(<<&1>>))
end
def to_hex_list(x) when is_binary(x) do
x
|> :erlang.binary_to_list()
|> to_hex_list()
end
def to_hex_string(x) when is_binary(x) do
x
|> to_hex_list()
|> to_hex_string()
end
def to_hex_string(x) when is_list(x) do
Enum.join(x, " ")
end
def to_little_ucs2(str) do
with utf16 when is_bitstring(utf16) <-
:unicode.characters_to_binary(
str,
:unicode,
{:utf16, :little}
) do
utf16
else
_ ->
error = ~s(failed to convert string "#{inspect(str)}" to ucs2 binary)
raise Tds.Error, error
end
end
def ucs2_to_utf(s) do
:binary.bin_to_list(s)
|> Enum.reject(&(&1 == 0))
|> to_string()
end
def to_boolean(<<1>>) do
true
end
def to_boolean(<<0>>) do
false
end
def error(error, _s) do
{:error, error}
end
end