changed
README.md
|
@@ -66,7 66,7 @@ $ mix test
|
66
66
|
```
|
67
67
|
|
68
68
|
The tests require your sql server database to be present on localhost. In case you are unable to run local instance of SQL server either using local installation on [windows](https://docs.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-installation-wizard-setup) or [linix](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup), docker image for [linux](https://hub.docker.com/r/microsoft/mssql-server-linux/)
|
69
|
-
|
69
|
You will need sqlcmd command line tools for some operations in test. Setup instructions can be found [here](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools)
|
70
70
|
|
71
71
|
Additionally SQL authentication needs to be used for connecting and testing. Check config/test.exs file for credentials used in unit testing.
|
changed
hex_metadata.config
|
@@ -24,4 24,4 @@
|
24
24
|
{<<"optional">>,false},
|
25
25
|
{<<"repository">>,<<"hexpm">>},
|
26
26
|
{<<"requirement">>,<<"~> 1.1">>}]]}.
|
27
|
- {<<"version">>,<<"1.0.5">>}.
|
27
|
{<<"version">>,<<"1.0.6">>}.
|
changed
lib/tds/protocol.ex
|
@@ -58,9 58,10 @@ defmodule Tds.Protocol do
|
58
58
|
mod.close(sock)
|
59
59
|
end
|
60
60
|
|
61
|
@spec ping(any) :: {:ok, any} | {:disconnect, Exception.t, any}
|
61
62
|
def ping(state) do
|
62
63
|
case send_query(~s{SELECT 'pong' as [msg]}, state) do
|
63
|
- {:ok, _, s} -> {:ok, s}
|
64
|
{:ok, _, s} -> {:ok, s}
|
64
65
|
{:error, err, s} -> {:disconnect, err, s}
|
65
66
|
end
|
66
67
|
end
|
|
@@ -121,7 122,7 @@ defmodule Tds.Protocol do
|
121
122
|
|
122
123
|
defp instance(opts, s) do
|
123
124
|
host = Keyword.fetch!(opts, :hostname)
|
124
|
- host = if is_binary(host), do: String.to_char_list(host), else: host
|
125
|
host = if is_binary(host), do: String.to_charlist(host), else: host
|
125
126
|
|
126
127
|
case :gen_udp.open(0, [:binary, {:active, false}, {:reuseaddr, true}]) do
|
127
128
|
{:ok, sock} ->
|
|
@@ -135,7 136,7 @@ defmodule Tds.Protocol do
|
135
136
|
|
136
137
|
defp connect(opts, s) do
|
137
138
|
host = Keyword.fetch!(opts, :hostname)
|
138
|
- host = if is_binary(host), do: String.to_char_list(host), else: host
|
139
|
host = if is_binary(host), do: String.to_charlist(host), else: host
|
139
140
|
port = s.itcp || opts[:port] || System.get_env("MSSQLPORT") || 1433
|
140
141
|
{port, _} = if is_binary(port), do: Integer.parse(port), else: {port, nil}
|
141
142
|
timeout = opts[:timeout] || @timeout
|
|
@@ -311,7 312,7 @@ defmodule Tds.Protocol do
|
311
312
|
case msg_send(msg, s) do
|
312
313
|
:ok ->
|
313
314
|
{:noreply, %{s | state: :prelogin}}
|
314
|
- {:error, reason} ->
|
315
|
{:error, reason, s} ->
|
315
316
|
error(%Tds.Error{message: "tcp send: #{reason}"}, s)
|
316
317
|
end
|
317
318
|
end
|
|
@@ -538,8 539,8 @@ defmodule Tds.Protocol do
|
538
539
|
mod.send(sock, pak)
|
539
540
|
end)
|
540
541
|
case msg_recv(<<>>, s) do
|
541
|
- {:disconnect, _ , ex} ->
|
542
|
- {:error, ex}
|
542
|
{:disconnect, _ex , _s}=res ->
|
543
|
res
|
543
544
|
buffer ->
|
544
545
|
new_data(buffer, %{s | state: :executing, pak_header: ""})
|
545
546
|
end
|
|
@@ -597,8 598,8 @@ defmodule Tds.Protocol do
|
597
598
|
end)
|
598
599
|
|
599
600
|
case msg_recv(<<>>, s) do
|
600
|
- {:disconnect, _ , ex} ->
|
601
|
- {:error, ex}
|
601
|
{:disconnect, ex , s} ->
|
602
|
{:error, ex, s}
|
602
603
|
buffer ->
|
603
604
|
new_data(buffer, %{s | state: :login})
|
604
605
|
end
|
changed
lib/tds/types.ex
|
@@ -458,14 458,10 @@ defmodule Tds.Types do
|
458
458
|
d_ctx = Decimal.get_context
|
459
459
|
d_ctx = %{d_ctx | precision: precision}
|
460
460
|
Decimal.set_context d_ctx
|
461
|
- d = Decimal.new pow10(value,(scale * -1))
|
462
|
- value = pow10(d.coef, d.exp)
|
463
|
- value =
|
464
461
|
case sign do
|
465
|
- 0 -> value * -1
|
466
|
- _ -> value
|
462
|
0 -> Decimal.new(-1, value, (scale * -1))
|
463
|
_ -> Decimal.new( 1, value, (scale * -1))
|
467
464
|
end
|
468
|
- Decimal.new value
|
469
465
|
end
|
470
466
|
|
471
467
|
def decode_char(_collation, <<data::binary>>) do
|
|
@@ -1026,11 1022,11 @@ defmodule Tds.Types do
|
1026
1022
|
String.length(p)
|
1027
1023
|
end
|
1028
1024
|
if precision <= 7 1 do
|
1029
|
- <<0x04, value::little-float-size(32)>>
|
1025
|
<<0x04, value::little-float-32>>
|
1030
1026
|
else
|
1031
1027
|
# up to 15 digits of precision https://docs.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql
|
1032
|
- <<0x08, value::little-float-size(64)>>
|
1033
|
- end
|
1028
|
<<0x08, value::little-float-64>>
|
1029
|
end
|
1034
1030
|
end
|
1035
1031
|
|
1036
1032
|
@doc """
|
changed
lib/tds/utils.ex
|
@@ -1,6 1,5 @@
|
1
1
|
defmodule Tds.Utils do
|
2
2
|
require Logger
|
3
|
- #alias Tds.Connection
|
4
3
|
|
5
4
|
def to_hex_list(x) when is_list(x) do
|
6
5
|
Enum.map x, &( Base.encode16(<<&1>>))
|
|
@@ -58,43 57,8 @@ defmodule Tds.Utils do
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
|
62
60
|
def reply(reply, {_, _} = from) do
|
63
61
|
GenServer.reply(from, reply)
|
64
62
|
true
|
65
63
|
end
|
66
|
-
|
67
|
- # Connection.next is undefined
|
68
|
- # def ready(%{queue: queue} = s) do
|
69
|
- # queue =
|
70
|
- # case :queue.out(queue) do
|
71
|
- # {{:value, {_, _, ref}}, q} ->
|
72
|
- # Process.demonitor(ref)
|
73
|
- # q
|
74
|
- # {:empty, q} ->
|
75
|
- # q
|
76
|
- # end
|
77
|
- # Connection.next(%{s | statement: "", queue: queue, state: :ready})
|
78
|
- # end
|
79
|
-
|
80
|
- def pow10(num,0), do: num
|
81
|
- def pow10(num,pow) when pow > 0 do
|
82
|
- pow10(10*num, pow - 1)
|
83
|
- end
|
84
|
-
|
85
|
- def pow10(num,pow) when pow < 0 do
|
86
|
- pow10(num/10, pow 1)
|
87
|
- end
|
88
|
-
|
89
|
- def pow(_, 0), do: 1
|
90
|
- def pow(a, 1), do: a
|
91
|
-
|
92
|
- def pow(a, n) when rem(n, 2) === 0 do
|
93
|
- tmp = pow(a, div(n, 2))
|
94
|
- tmp * tmp
|
95
|
- end
|
96
|
-
|
97
|
- def pow(a, n) do
|
98
|
- a * pow(a, n-1)
|
99
|
- end
|
100
64
|
end
|
changed
mix.exs
|
@@ -3,7 3,7 @@ defmodule Tds.Mixfile do
|
3
3
|
|
4
4
|
def project do
|
5
5
|
[ app: :tds,
|
6
|
- version: "1.0.5",
|
6
|
version: "1.0.6",
|
7
7
|
elixir: "~> 1.0",
|
8
8
|
deps: deps(),
|
9
9
|
test_coverage: [tool: ExCoveralls],
|