<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><br></div><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><br></div><div>You don’t need mnesia at all to use QLC. Just execute qlc:e(Q) directly.</div><div><br></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 type="cite"><font face="arial" size="2"><div style="margin: 0px; padding: 0px; font-family: arial; font-size: 10pt; word-wrap: break-word;">Hello,</div><p style="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;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;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;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;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;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;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;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;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;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;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><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;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;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;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;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;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;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;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;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;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;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;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;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;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--><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>
<!--WM_COMPOSE_SIGNATURE_END--></font>_______________________________________________<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<br></blockquote></div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div><div>Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.</div><div><a href="http://feuerlabs.com">http://feuerlabs.com</a></div></div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></body></html>