[erlang-questions] Iterating (Page scrolling) over Mnesia database

David King dking@REDACTED
Mon Sep 24 19:51:52 CEST 2007

> 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
> List = select rows with some query starting from 10000th record and  
> max 200.
> Thanks again.

You might want to start by using your internal IDs, like

qlc:q([ { X#article.title,
         || X <- qlc:table(article),
            X#article.id > 100,
            X#article.id < 110 ]).

That's easiest to understand for me, anyway. But if you want paging  
based on the results rather than the table (if you need constant- 
sized pages, like for visual paging for a web site), take a look at  
qlc:table/2, especially this part:

> The binary callback function LookupFun is used for looking up  
> objects in the table. The first argument Position is the key  
> position or an indexed position and the second argument Keys is a  
> sorted list of unique values. The return value is to be a list of  
> all objects (tuples) such that the element at Position is a member  
> of Keys. Any other return value is immediately returned as value of  
> the query evaluation

I haven't tried it, but it's a good place to start looking, at least

More information about the erlang-questions mailing list