[erlang-questions] QLC Cursor confusion

Ignas Vyšniauskas <>
Wed Feb 22 15:38:34 CET 2012

Hi Erlangers,

I'm somewhat confused with the correct usage of QLC Cursors. I'd like to
return the cursor (or a equivalently a reference to it), so that the
receiver could perform consecutive calls to qlc:next_answers(CursorRef,
N). But as far as I understand, this is not quite possible. Here is me
failing to make friends with QLC (sorry for the mangled formatting):

40> Q = qlc:q([P || P <- mnesia:table('number.info'),
P#'number.info'.owner_id == <<"13">>]).
41> qlc:cursor(Q).

** exception exit: {aborted,no_transaction}
     in function  mnesia:abort/1
     in call from mnesia:pre_qlc/2
     in call from qlc:call/4
     in call from qlc:table_handle/3
     in call from qlc:setup_le/3
     in call from qlc:setup_quals/6
     in call from qlc:setup_quals/4
     in call from qlc:setup_le/3

Okayy, let's try it in a transaction:

42> {atomic, QR} = mnesia:transaction(fun() -> qlc:cursor(Q) end).


Cool, it works, but...

43> qlc:next_answers(QR, 1).
** exception error: {qlc_cursor_pid_no_longer_exists,<0.436.0>}
     in function  qlc:next_loop/3

Hm, but...

44> mnesia:transaction(fun() -> qlc:next_answers(QR, 1) end).

I'm confused. Does that mean the cursor lives in some process owned by
mnesia and I can only access it from within a single transaction? What
am I doing wrong here?


More information about the erlang-questions mailing list