This worked, but is there a way to do page scrolling with explicit start position and number of rows (without skipping manually). Let's say, I am sorting by name, I can't use id to control the start position. I would like to say <br>List = select rows with some query starting from 10000th record and max 200.<br>Thanks again.<br><br><br><b><i>David King <dking@ketralnis.com></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> > I am looking for a way to iterate over the results in the Mnesia <br>> that are ordered by some element, in other words equivalent of<br>> SELECT * FROM TABLE ORDER BY MYFIELD -- that can return results in <br>> cursor like fashion<br><br>The idea is to combine query handles, like this:<br><br>mnesia:transaction(fun() -><br> % give me all of the authors from the author table with an ID over 10<br> Q1=qlc:q([ X || X <- mnesia:table(author),
X#author.id > 10 ]),<br><br> % sort them by name<br> Q2=qlc:sort(Q1,<br> {order, % I'm using the OrderFun form here. See <br>file_sorter<br> fun(Author1,Author2) -><br> Author1#author.name < Author2#author.name<br> end}),<br><br> % and run the query<br> qlc:eval(Q2)<br>end)<br><br>Note that these query handles aren't evaluated until you ask them to <br>be (with fold, cursor, eval, etc), so it's not as inefficient as <br>sorting them all in memory if, for instance, indexes are available.. <br>To iterate over them, use qlc:fold or qlc:cursor instead of qlc:eval:<br><br>qlc:fold(fun(Author,AccIn) -><br> Author#author.id+AccIn<br> end, 0, Q2).<br><br>That would give me the sum of all of the IDs in the results (which is <br>a bit contrived, but you get the idea)<br><br>More information at http://www.erlang.org/doc/man/qlc.html<br><br><br>> Or page scrolling like<br>>
SELECT * FROM TABLE ORDER BY MYFIELD where rownum > 100 and rownum <br>> < 200;<br>> I see foldl and foldr methods can iterate, and qlc can query, but <br>> can someone point me how to implement Cursor or page scrolling <br>> behavior.<br>><br>> Thanks in advance.<br>> -Shahzad Bhatti<br>><br>> Moody friends. Drama queens. Your life? Nope! - their life, your <br>> story.<br>> Play Sims Stories at Yahoo! Games.<br>> _______________________________________________<br>> erlang-questions mailing list<br>> erlang-questions@erlang.org<br>> http://www.erlang.org/mailman/listinfo/erlang-questions<br><br></blockquote><br><p>
<hr size=1>Don't let your dream ride pass you by. <a href="http://us.rd.yahoo.com/evt=51200/*http://autos.yahoo.com/index.html;_ylc=X3oDMTFibjNlcHF0BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDYXV0b3MtZHJlYW1jYXI-"> Make it a reality</a> with Yahoo! Autos.