{atomic,[R]}={atomic,[{ios,2,"hhh"},{ios,1,"hhh"}]}
this produces an error.What am trying to do is basicaaly fetch multiple rows from mnesia table and use case statement to handle any error(if there does not exist a record for which i am searching).Whenever there is one or zero tuple corresponding to the item searched it works fine but whenn there is more than one tuple it throws the error.Below is full code
x( Artist) ->
Query = fun() ->
mnesia:match_object({ios,'_', Artist } )
end,
X=case mnesia:transaction( Query) of
{atomic,[R]} ->
io:format("Text found in Android : ~p~n", [R#ios.txt]) ;
{atomic,[]} ->
Id=1000,
io:format("No records with ID = ~p~n", [Id]);
{aborted,{no_exists,ios}}->
hi
end,
X.
If your request find multiple row, the answer is (I guess) {atomic,List}
where List is a list that contains more than one element and thus cannot match with [R]
which is a list of one single element.
What you can do is receive the list and traverse it to print the results;
x( Artist) ->
Query = fun() ->
mnesia:match_object({ios,'_', Artist } )
end,
case mnesia:transaction( Query) of
{atomic,[]} ->
Id=1000,
io:format("No records with ID = ~p~n", [Id]);
{atomic,L} ->
[io:format("Text found in Android : ~p~n", [R#ios.txt]) || R <- L] ;
{aborted,{no_exists,ios}}->
hi
end.