Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tds/binary_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule Tds.BinaryUtils do
@doc """
An unsigned 4-byte (32-bit) value. The range when used as a numeric value is 0 to (2^32)- 1.
"""
defmacro dword, do: quote(do: unsigned - 32)
defmacro dword, do: quote(do: little - unsigned - 32)

@doc """
An unsigned single byte (8-bit) value representing a character. The range is 0 to 255.
Expand Down
20 changes: 9 additions & 11 deletions lib/tds/protocol/login7.ex
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,14 @@ defmodule Tds.Protocol.Login7 do
# Return the current pid
# If that fails return a "default" pid
defp pid! do
value =
self()
|> :erlang.pid_to_list()
|> to_string()
|> String.split(".")
|> Enum.at(1)
|> String.to_integer()

<<value::dword()>>
rescue
_ -> @client_pid
System.pid()
|> Integer.parse()
|> case do
{pid, ""} ->
<<pid::dword()>>

_ ->
@client_pid
end
end
end
13 changes: 13 additions & 0 deletions test/host_id_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule HostIdTest do
use ExUnit.Case, async: true

import Tds.TestHelper, only: [opts: 0]

test "Check that SELECT HOST_ID() matches System.pid()" do
{:ok, conn} = Tds.start_link(opts())
{:ok, %Tds.Result{rows: [[host_id]]}} = Tds.query(conn, "SELECT HOST_ID()", [])

pid = System.pid()
assert pid === String.trim(host_id)
end
end