How Mnemosyne cursors are used ?
Massimo Cesaro
massimo.cesaro@REDACTED
Wed Nov 12 08:54:46 CET 2003
I'd like to have a function that when called returns, up to N records
from a Mnesia table. The records are extracted using a Mnemosyne query,
and I thought the I could do something like this:
get_page(StartDate, EndDate, Result, MaxLines) ->
Q = query [C || C <- table(cdr),
C.date >= StartDate,
C.date =< EndDate,
C.result = Result
]
end,
F= fun() ->
Cursor = mnemosyne:cursor(Q),
L = mnemosyne:next_answers(Cursor, MaxLines, MaxLines),
[Cursor, L]
end,
% Get the first MaxLines records
{R, [C, L]}= mnesia:transaction(F),
% format and display records
format_cdr(L),
% Get another block of records
K = mnesia:transaction(fun() -> mnemosyne:next_answers(C) end),
format_cdr(K);
mnemosyne:delete_cursors(Cursors);
I get the first block correctly, but on the second
mnemosyne:next_answers() call, I have a "wrong transaction" error.
Clearly this is not the way the cursors should be used, but then how can
I query the database in discrete blocks (let say that I want to print
the records on different pages of a report), maintaining the cursor
status between separate calls ?
Puzzled...
Massimo
More information about the erlang-questions
mailing list