Skip to content

Commit

Permalink
Moved db connection settings from start_link to protocol fixing multi…
Browse files Browse the repository at this point in the history
…ple connection issues. paired: Jae
  • Loading branch information
toddharding committed Mar 9, 2017
1 parent 69ea6e4 commit 8c4ee39
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
7 changes: 0 additions & 7 deletions lib/mssqlex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ defmodule Mssqlex do
"""
@spec start_link(Keyword.t) :: {:ok, pid}
def start_link(opts) do
opts = opts
|> Keyword.put_new(:odbc_driver, "{ODBC Driver 13 for SQL Server}")
|> Keyword.put_new(:hostname, System.get_env("MSSQL_HST") || "localhost")
|> Keyword.put_new(:database, System.get_env("MSSQL_DB"))
|> Keyword.put_new(:username, System.get_env("MSSQL_UID"))
|> Keyword.put_new(:password, System.get_env("MSSQL_PWD"))

DBConnection.start_link(Mssqlex.Protocol, opts)
end

Expand Down
12 changes: 6 additions & 6 deletions lib/mssqlex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ defmodule Mssqlex.Protocol do
| {:error, Exception.t}
def connect(opts) do
conn_opts = [
{"DRIVER", opts[:odbc_driver]},
{"SERVER", opts[:hostname]},
{"DATABASE", opts[:database]},
{"UID", opts[:username]},
{"PWD", opts[:password]}
{"DRIVER", opts[:odbc_driver] || "{ODBC Driver 13 for SQL Server}"},
{"SERVER", opts[:hostname] || System.get_env("MSSQL_HST") || "localhost"},
{"DATABASE", opts[:database] || System.get_env("MSSQL_DB")},
{"UID", opts[:username] || System.get_env("MSSQL_UID")},
{"PWD", opts[:password] || System.get_env("MSSQL_PWD")}
]
conn_str = Enum.reduce(conn_opts, "", fn {key, value}, acc ->
acc <> "#{key}=#{value};" end)
Expand Down Expand Up @@ -185,7 +185,7 @@ defmodule Mssqlex.Protocol do
{status, message, new_state} = do_query(query, params, opts, state)

case new_state.mssql do
:idle ->
:idle ->
with {:ok, _, post_commit_state} <- handle_commit(opts, new_state)
do
{status, message, post_commit_state}
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Mssqlex.Mixfile do

def project do
[app: :mssqlex,
version: "0.4.0",
version: "0.4.1",
description: "Adapter to Microsoft SQL Server. Using DBConnection and ODBC.",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
Expand Down

0 comments on commit 8c4ee39

Please sign in to comment.