Skip to content

Commit

Permalink
Patched transaction logic. 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jae Bach Hardie committed Mar 6, 2017
1 parent 5fa9f00 commit 58efe69
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ by adding `mssqlex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:mssqlex, "~> 0.1.0"}]
[{:mssqlex, "~> 0.1"}]
end
```

Expand Down
14 changes: 10 additions & 4 deletions lib/mssqlex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ defmodule Mssqlex.Protocol do
{:ok, result, state}
| {:error | :disconnect, Exception.t, state}
def handle_begin(_opts, state) do
{:ok, %Result{num_rows: 0}, Map.put(state, :mssql, :transaction)}
case state.mssql do
:idle -> {:ok, %Result{num_rows: 0}, %{state | mssql: :transaction}}
:transaction -> {:error,
%Mssqlex.Error{message: "Already in transaction"}}
:auto_commit -> {:error,
%Mssqlex.Error{message: "Transactions not allowed in autocommit mode"}}
end
end

@doc false
Expand All @@ -106,7 +112,7 @@ defmodule Mssqlex.Protocol do
{:error | :disconnect, Exception.t, state}
def handle_commit(_opts, state = %{pid: pid}) do
case ODBC.commit(pid) do
:ok -> {:ok, %Result{}, state}
:ok -> {:ok, %Result{}, %{state | mssql: :idle}}
{:error, reason} -> {:error, reason, state}
end
end
Expand All @@ -117,8 +123,8 @@ defmodule Mssqlex.Protocol do
{:error | :disconnect, Exception.t, state}
def handle_rollback(_opts, state = %{pid: pid}) do
case ODBC.rollback(pid) do
:ok -> {:ok, %Result{}, state}
{:error, reason} -> {:error, reason. state}
:ok -> {:ok, %Result{}, %{state | mssql: :idle}}
{:error, reason} -> {:disconnect, reason. state}
end
end

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.1.0",
version: "0.1.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 58efe69

Please sign in to comment.