Skip to content

Commit

Permalink
Fixed #2. Check that transaction was committed via cmd status
Browse files Browse the repository at this point in the history
  • Loading branch information
Kozlov Yakov committed Jul 13, 2017
1 parent 21ca0f4 commit c60db54
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Expand Up @@ -4,7 +4,7 @@

{deps, [
{lager, "3.2.1"},
{epgsql, "3.2.0"},
{epgsql, "3.3.0"},
{poolboy, "1.4.2"}
]}.

Expand Down
4 changes: 2 additions & 2 deletions rebar.lock
@@ -1,11 +1,11 @@
{"1.1.0",
[{<<"epgsql">>,{pkg,<<"epgsql">>,<<"3.2.0">>},0},
[{<<"epgsql">>,{pkg,<<"epgsql">>,<<"3.3.0">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.8">>},1},
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.1">>},0},
{<<"poolboy">>,{pkg,<<"poolboy">>,<<"1.4.2">>},0}]}.
[
{pkg_hash,[
{<<"epgsql">>, <<"2277244364628CCFC271A843F4B014729D0799BCB99B70C2216BCFD6DD6B409E">>},
{<<"epgsql">>, <<"974A578340E52012CBAB820CE756E7ED1DF1BAF0110C59A6753D8337A2CF9454">>},
{<<"goldrush">>, <<"2024BA375CEEA47E27EA70E14D2C483B2D8610101B4E852EF7F89163CDB6E649">>},
{<<"lager">>, <<"EEF4E18B39E4195D37606D9088EA05BF1B745986CF8EC84F01D332456FE88D17">>},
{<<"poolboy">>, <<"619519C7708DD001CE9B61908218D03FF582C3BA44A1E129D694376C2B332D87">>}]}
Expand Down
5 changes: 4 additions & 1 deletion src/epgpool.erl
Expand Up @@ -58,7 +58,10 @@ transaction(Fun, Timeout) ->
Err;
Other ->
{ok, [], []} = squery(C, "COMMIT"),
Other
case epgsql:get_cmd_status(C) of
{ok, commit} -> Other;
{ok, rollback} -> {error, rollback}
end
catch Class:Reason ->
Stacktrace = erlang:get_stacktrace(),
catch (squery(C, "ROLLBACK")),
Expand Down
6 changes: 5 additions & 1 deletion test/epgpool_SUITE.erl
Expand Up @@ -102,4 +102,8 @@ transaction_test(_Config) ->
end)
end),
timer:sleep(200),
{ok, _, [{<<"t2">>}]} = epgpool:squery("select name from test where id = 1").
{ok, _, [{<<"t2">>}]} = epgpool:squery("select name from test where id = 1"),
{error, rollback} = epgpool:transaction(fun(C) ->
{error, _} = epgsql:squery(C, "SELECT * FROM undefined_table;"),
ok
end).

0 comments on commit c60db54

Please sign in to comment.