[erlang-questions] Help! Drowning in qlc documentation
lloyd@REDACTED
lloyd@REDACTED
Sat Oct 18 17:46:48 CEST 2014
Hello,
I really really want to understand qlc. But that's another story. Here's my immediate problem:
I have a simple dets db that stores:
-record(note, {date, subject, note}).
I want to fetch all notes equal or less than a given date. Leveraging Joe Armstrong's do/1 function (Programming Erlang, 2007, p326), I wrote a query function as so:
do(Q) ->
F = fun() -> qlc:e(Q) end,
{atomic, Val} = mnesia:transaction(F),
Val.
get_notes(Date) ->
open_notes_db(),
do(qlc:q([Record || Record <- dets:table(nit_notes), Record#note.date =< Date])),
close_notes_db().
When I run get_notes/1, I get this:
36> notes_store:get_notes(Date).
** exception error: no match of right hand side value {aborted,{node_not_running,'nit_notes@REDACTED'}}
in function notes_store:do/1 (/home/lloyd/nit_host/nit_notes/site/src/notes_store.erl, line 53)
in call from notes_store:get_notes/1 (/home/lloyd/nit_host/nit_notes/site/src/notes_store.erl, line 59)
This suggests that my dets db is not open, but I did that in get_notes/1:
open_notes_db() ->
File = nit_notes,
{ok, nit_notes} = dets:open_file(File,
[{keypos,#note.date}, {type,bag}]).
Which, in the shell, returns:
29> notes_store:open_notes_db().
{ok,nit_notes}
If I run:
qlc:q([Record#note.note || Record <- dets:table(nit_notes), Record#note.date =< Date ])
...in the shell, I get:
{qlc_handle,{qlc_lc,#Fun<erl_eval.20.90072148>, {qlc_opt,false,false,-1,any,[],any,524288,allowed}}}
Yes, I know that this is a query handle. But what in world does it mean? If I plug this mess it into the shell, I get:
1> Q = qlc:q([Record#note.note || Record <- dets:table(nit_notes), Record#note.date =< Date ]).
2> qlc:eval(Q).
** exception error: bad argument
in function dets:safe_fixtable/2
called as dets:safe_fixtable(nit_notes,true)
in call from qlc:call/4 (qlc.erl, line 3759)
in call from qlc:table_handle/3 (qlc.erl, line 2616)
in call from qlc:setup_le/3 (qlc.erl, line 2381)
in call from qlc:setup_quals/6 (qlc.erl, line 2480)
in call from qlc:setup_quals/4 (qlc.erl, line 2438)
in call from qlc:setup_le/3 (qlc.erl, line 2377)
in call from qlc:eval/2 (qlc.erl, line 290)
Which, again, suggests a problem with my dets table. But I don't know what.
Or, is it possible that my problem is with mnesia:transactions/1 in do/1? Docs do say that qlc should work with dets, but I don't see a dets:transactions/1.
How can I diagnose and fix?
Many thanks,
LRP
*********************************************
My books:
THE GOSPEL OF ASHES
http://thegospelofashes.com
Strength is not enough. Do they have the courage
and the cunning? Can they survive long enough to
save the lives of millions?
FREEIN' PANCHO
http://freeinpancho.com
A community of misfits help a troubled boy find his way
AYA TAKEO
http://ayatakeo.com
Star-crossed love, war and power in an alternative
universe
Available through Amazon or by request from your
favorite bookstore
**********************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141018/9abcd7a1/attachment.htm>
More information about the erlang-questions
mailing list