changed
README.md
|
@@ -11,7 +11,7 @@ Add Tds as a dependency in your `mix.exs` file.
|
11
11
|
|
12
12
|
```elixir
|
13
13
|
def deps do
|
14
|
- [{:tds, "~> 1.0.2"} ]
|
14
|
+ [{:tds, "~> 1.0.4"} ]
|
15
15
|
end
|
16
16
|
```
|
changed
hex_metadata.config
|
@@ -17,9 +17,11 @@
|
17
17
|
[[{<<"app">>,<<"decimal">>},
|
18
18
|
{<<"name">>,<<"decimal">>},
|
19
19
|
{<<"optional">>,false},
|
20
|
+ {<<"repository">>,<<"hexpm">>},
|
20
21
|
{<<"requirement">>,<<"~> 1.4">>}],
|
21
22
|
[{<<"app">>,<<"db_connection">>},
|
22
23
|
{<<"name">>,<<"db_connection">>},
|
23
24
|
{<<"optional">>,false},
|
25
|
+ {<<"repository">>,<<"hexpm">>},
|
24
26
|
{<<"requirement">>,<<"~> 1.1">>}]]}.
|
25
|
- {<<"version">>,<<"1.0.3">>}.
|
27
|
+ {<<"version">>,<<"1.0.4">>}.
|
changed
lib/tds/protocol.ex
|
@@ -58,9 +58,11 @@ defmodule Tds.Protocol do
|
58
58
|
mod.close(sock)
|
59
59
|
end
|
60
60
|
|
61
|
- def ping(s) do
|
62
|
-
|
63
|
- {:ok, s}
|
61
|
+ def ping(state) do
|
62
|
+ case send_query(~s{SELECT 'pong' as [msg]}, state) do
|
63
|
+ {:ok, s} -> {:ok, s}
|
64
|
+ {:error, err, s} -> {:disconnect, err, s}
|
65
|
+ end
|
64
66
|
end
|
65
67
|
|
66
68
|
def checkout(%{sock: {_mod, sock}} = s) do
|
|
@@ -482,8 +484,9 @@ defmodule Tds.Protocol do
|
482
484
|
columns
|
483
485
|
end
|
484
486
|
num_rows = done.rows;
|
485
|
- rows =
|
486
|
- if rows != nil, do: Enum.reverse(rows), else: rows
|
487
|
+ # rows are correctly orrdered when they were parsed, so below is not needed anymore
|
488
|
+ # rows =
|
489
|
+ # if rows != nil, do: Enum.reverse(rows), else: rows
|
487
490
|
rows = if num_rows == 0 && rows == nil, do: [], else: rows
|
488
491
|
|
489
492
|
result = %Tds.Result{columns: columns, rows: rows, num_rows: num_rows}
|
changed
lib/tds/types.ex
|
@@ -1011,7 +1011,26 @@ defmodule Tds.Types do
|
1011
1011
|
<<0>>
|
1012
1012
|
end
|
1013
1013
|
def encode_data(@tds_data_type_floatn, value, _) do
|
1014
|
- <<0x04, value::little-float-size(32)>>
|
1014
|
+ d_ctx = Decimal.get_context
|
1015
|
+ d_ctx = %{d_ctx | precision: 38}
|
1016
|
+ Decimal.set_context d_ctx
|
1017
|
+ value_list = Decimal.new(value)
|
1018
|
+ |> Decimal.abs
|
1019
|
+ |> Decimal.to_string(:scientific)
|
1020
|
+ |> String.split(".")
|
1021
|
+ precision =
|
1022
|
+ case value_list do
|
1023
|
+ [p,s] ->
|
1024
|
+ String.length(p) + String.length(s)
|
1025
|
+ [p] ->
|
1026
|
+ String.length(p)
|
1027
|
+ end
|
1028
|
+ if precision <= 7 + 1 do
|
1029
|
+ <<0x04, value::little-float-size(32)>>
|
1030
|
+ else
|
1031
|
+ # 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
|
1015
1034
|
end
|
1016
1035
|
|
1017
1036
|
@doc """
|
changed
lib/tds/utils.ex
|
@@ -85,4 +85,16 @@ defmodule Tds.Utils do
|
85
85
|
def pow10(num,pow) when pow < 0 do
|
86
86
|
pow10(num/10, pow + 1)
|
87
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
|
88
100
|
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.3",
|
6
|
+ version: "1.0.4",
|
7
7
|
elixir: "~> 1.0",
|
8
8
|
deps: deps(),
|
9
9
|
test_coverage: [tool: ExCoveralls],
|