[erlang-questions] Can't fill in the mnesia table

Dániel Szoboszlay <>
Mon Jul 10 16:46:56 CEST 2017


Hi,

Your code works for me (apart from the obvious race condition that you may
end up with more than 4 records in the table if at least two processes
execute the code concurrently), so my best guess is that the
mnesia:transaction(T3) call fails in your database for some reason. Try
capturing it's return value and adding it to the debug printout!

Cheers,
Daniel

On Mon, 10 Jul 2017 at 09:43 Abhishek Ranjan <>
wrote:

> I wrote this code snippet:
>
> *Player=t:user(List),
>         CatchAll=[{'_',[],['$_']}],
>         NameList=mnesia:dirty_select(player, CatchAll),
>           if
>               (length(NameList)<4)->
>                   T3 = fun() ->
>                   X3 = #player{name=Player
>                                 },
>                       mnesia:write(X3)
>                       end,
>                       mnesia:transaction(T3),
>                   NameList1=mnesia:dirty_select(player, CatchAll),
>                   ?io:format("1The value of NameList1 is ~p~n",[NameList1]),
>                   ok;
>               (length(NameList)==4)->
>                   ?io:format("2The value of NameList is ~p~n",[NameList])
>           end,       *
>
> Here, each time a call a module t:user I get a name which i have stored in
> Player and want to keep storing these names till there are 4 of them but
> each i time I run this I get an empty value of Namelist as [], instead of a
> list filled with players name.
>
> Any Idea on why this is happening?
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170710/9c4ebffb/attachment.html>


More information about the erlang-questions mailing list