<font face="arial" size="2"><p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">Hello,</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">I really really want to understand qlc. But that's another story. Here's my immediate problem:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">I have a simple dets db that stores:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">-record(note, {date, subject, note}).</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">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:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">do(Q) -><br /> F = fun() -> qlc:e(Q) end,<br /> {atomic, Val} = mnesia:transaction(F),<br /> Val.</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">get_notes(Date) -><br /> open_notes_db(),<br /> do(qlc:q([Record || Record <- dets:table(nit_notes), Record#note.date =< Date])),<br /> close_notes_db().</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">When I run get_notes/1, I get this:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">36> notes_store:get_notes(Date).<br />** exception error: no match of right hand side value {aborted,{node_not_running,'nit_notes@127.0.0.1'}}<br /> in function notes_store:do/1 (/home/lloyd/nit_host/nit_notes/site/src/notes_store.erl, line 53)<br /> in call from notes_store:get_notes/1 (/home/lloyd/nit_host/nit_notes/site/src/notes_store.erl, line 59)</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">This suggests that my dets db is not open, but I did that in get_notes/1:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">open_notes_db() -><br /> File = nit_notes,<br /> {ok, nit_notes} = dets:open_file(File,<br /> [{keypos,#note.date}, {type,bag}]).</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">Which, in the shell, returns:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">29> notes_store:open_notes_db().<br />{ok,nit_notes}</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">If I run:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">qlc:q([Record#note.note || Record <- dets:table(nit_notes), Record#note.date =< Date ])</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">...in the shell, I get:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">{qlc_handle,{qlc_lc,#Fun<erl_eval.20.90072148>, {qlc_opt,false,false,-1,any,[],any,524288,allowed}}}</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">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:</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">1> Q = qlc:q([Record#note.note || Record <- dets:table(nit_notes), Record#note.date =< Date ]).</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">2> qlc:eval(Q).</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">** exception error: bad argument<br /> in function dets:safe_fixtable/2<br /> called as dets:safe_fixtable(nit_notes,true)<br /> in call from qlc:call/4 (qlc.erl, line 3759)<br /> in call from qlc:table_handle/3 (qlc.erl, line 2616)<br /> in call from qlc:setup_le/3 (qlc.erl, line 2381)<br /> in call from qlc:setup_quals/6 (qlc.erl, line 2480)<br /> in call from qlc:setup_quals/4 (qlc.erl, line 2438)<br /> in call from qlc:setup_le/3 (qlc.erl, line 2377)<br /> in call from qlc:eval/2 (qlc.erl, line 290)</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">Which, again, suggests a problem with my dets table. But I don't know what.</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">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.</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">How can I diagnose and fix?</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">Many thanks,</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">LRP</p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<!--WM_COMPOSE_SIGNATURE_START-->
<p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">*********************************************<br />My books:<br /><br />THE GOSPEL OF ASHES<br />http://thegospelofashes.com<br /><br />Strength is not enough. Do they have the courage <br />and the cunning? Can they survive long enough to <br />save the lives of millions? <br /><br />FREEIN' PANCHO<br />http://freeinpancho.com<br /><br />A community of misfits help a troubled boy find his way <br /><br />AYA TAKEO<br />http://ayatakeo.com<br /><br />Star-crossed love, war and power in an alternative <br />universe<br /><br />Available through Amazon or by request from your <br />favorite bookstore<br /><br /><br />**********************************************</p>
<!--WM_COMPOSE_SIGNATURE_END--></font>