<font face="arial" size="2"><p style="margin:0;padding:0;font-family: arial; font-size: 10pt; word-wrap: break-word;">Many thanks, Ulf,</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;">That did the trick.</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;">Best wishes,</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;">-----Original Message-----<br />From: "Ulf Wiger" <ulf@feuerlabs.com><br />Sent: Sunday, October 19, 2014 3:33am<br />To: lloyd@writersglen.com<br />Cc: "erlang questions" <erlang-questions@erlang.org><br />Subject: Re: [erlang-questions] Help! Drowning in qlc documentation<br /><br /></p>
<div id="SafeStyles1413743036">
<div>The {aborted,{node_not_running,'<a href="mailto:nit_notes@127.0.0.1">nit_notes@127.0.0.1</a>’}} message comes from mnesia, as you’re trying to run a mnesia transaction without actually having a mnesia database.</div>
<div>You don’t need mnesia at all to use QLC. Just execute qlc:e(Q) directly.</div>
<div>BR,</div>
<div>Ulf W</div>
<br />
<div>
<div>On 18 Oct 2014, at 17:46, <a href="mailto:lloyd@writersglen.com">lloyd@writersglen.com</a> wrote:</div>
<br class="Apple-interchange-newline" />
<blockquote>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">Hello,</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">I have a simple dets db that stores:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">-record(note, {date, subject, note}).</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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.</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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().</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">When I run get_notes/1, I get this:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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,'<a href="mailto:nit_notes@127.0.0.1">nit_notes@127.0.0.1</a>'}}<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)</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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}]).</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">Which, in the shell, returns:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">29> notes_store:open_notes_db().<br />{ok,nit_notes}</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">If I run:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">qlc:q([Record#note.note || Record <- dets:table(nit_notes), Record#note.date =< Date ])</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">...in the shell, I get:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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}}}</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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:</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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 ]).</div>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">2> qlc:eval(Q).</div>
<div style="margin: 0px; padding: 0px; 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)</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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.</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; 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.</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">How can I diagnose and fix?</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">Many thanks,</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">LRP</div>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<p style="margin:0;padding:0;margin: 0; padding: 0; font-family: arial; font-size: 10pt; word-wrap: break-word;"> </p>
<div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">*********************************************<br />My books:<br /><br />THE GOSPEL OF ASHES<br /><a href="http://thegospelofashes.com">http://thegospelofashes.com</a><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 />**********************************************</div>
_______________________________________________<br />erlang-questions mailing list<br /><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br />http://erlang.org/mailman/listinfo/erlang-questions</blockquote>
</div>
<br />
<div>
<div>
<div>Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div>
<div><a href="http://feuerlabs.com">http://feuerlabs.com</a></div>
</div>
</div>
</div></font>