Retrieving zero answers using mnemosyne

Sean Hinde <>
Tue Dec 21 18:44:31 CET 1999


All,

I am writing an application which will retrieve zero or one answers from a
mnemosyne query but have hit a problem.

mnemosyne:next_answers/3 appears to be the only way to get a single answer
from a match type query but if there are no matches it hangs. The obvious
thing to do is set Nmin to 0 but this is not allowed.

Has anyone come across this problem before or have any suggestions of how to
retrieve a single match out of potentially more then one result?

Thanks,

Sean

%% Example of what I am trying to achieve..
assign(User) ->
    Handle = 
	query
	    [ I.ip || I <- table(ip_pool),
		      I.user == [] ]
	end,
    F = fun() ->
		Cursor = mnemosyne:cursor(Handle),
		case mnemosyne:next_answers(Cursor,1,1) of
		    [] ->
			mnesia:abort(no_spare_ip_addresses);
		    [IP] ->
			mnesia:write(#ip_pool{ip = IP,
					      user = User,
					      timestamp = now()}),
			mnemosyne:delete_cursor(Cursor),
			IP
		end
	end,
    mnesia:transaction(F).



More information about the erlang-questions mailing list