[erlang-questions] How to return all records in dets

Ulf Wiger ulf@REDACTED
Fri May 30 22:51:53 CEST 2014


Yes, sorry about the tab2list/1 error. I see now that I didn’t actually verify that one.

But…

17> dets:open_file("d", []).
{ok,"d"}
18> dets:insert("d", [{a,1},{b,2}]).
ok
19> dets:select("d", ets:fun2ms(fun(X) -> X end)). 
[{b,2},{a,1}]
20> dets:select("d", ets:fun2ms(fun(X) -> X end)).
[{b,2},{a,1}]
21> dets:match_object("d",'_').                   
[{b,2},{a,1}]

Are you sure your open function actually names the dets table ‘visitors’?

BR,
Ulf W

On 30 May 2014, at 22:46, lloyd@REDACTED wrote:

> Hi Ulf,
> 
> No cigar.
> 
> First I tried in Erlang shell:
> 
> (nitrogen@REDACTED)36> visitor_store:open_visitor_db().
> dets opened: visitors
> void
> (nitrogen@REDACTED)37> dets:tab2list(visitors).
> ** exception error: undefined function dets:tab2list/1
> 
> (I'm running R17.0; noticed that tab2list/1 is not in docs. We do have to_ets/1, but I haven't tried that yet.)
> 
> 
> (nitrogen@REDACTED)38> dets:select(visitors, [{'_',[], ['$_']}]).
> ** exception error: bad argument
>     in function  dets:select/2
>        called as dets:select(visitors,[{'_',[],['$_']}])
> 
> (Maybe my typo, but I can't see it.)
> 
> (nitrogen@REDACTED)39> dets:match_object(visitors, '_').
> ** exception error: bad argument
>     in function  dets:match_object/2
>        called as dets:match_object(visitors,'_')
> 
> So I created some functions:
> 
> dump_visitors() ->
>   dets:tab2list(visitors).
> 
> dump_visitors1() ->
>   dets:select(visitors, [{'_', [], ['$_']}]).
> 
> dump_visitors2() ->
>   dets:match_object(visitors, '_').
> 
> And called them in the shell:
> 
> (nitrogen@REDACTED)40> l(visitor_store).
> {module,visitor_store}
> 
> (nitrogen@REDACTED)41> visitor_store:dump_visitors().
> ** exception error: undefined function dets:tab2list/1
> 
> (nitrogen@REDACTED)42> visitor_store:dump_visitors1().
> ** exception error: bad argument
>     in function  dets:select/2
>        called as dets:select(visitors,[{'_',[],['$_']}])
> 
> (nitrogen@REDACTED)43> visitor_store:dump_visitors2().
> ** exception error: bad argument
>     in function  dets:match_object/2
>        called as dets:match_object(visitors,'_')
> 
> I feel like I'm jinxed.
> 
> Thanks,
> 
> Lloyd
> 
> 
> 
> 
> -----Original Message-----
> From: "Ulf Wiger" <ulf@REDACTED>
> Sent: Friday, May 30, 2014 4:08pm
> To: lloyd@REDACTED
> Cc: "erlang questions" <erlang-questions@REDACTED>
> Subject: Re: [erlang-questions] How to return all records in dets
> 
> 
> ets:tab2list(Tab).
> 
> ets:select(Tab, [{‘_’, [], [‘$_’]}]).
> 
> ets:select(Tab, ets:fun2ms(fun(X) -> X end).
> 
> ets:match_object(Tab, ‘_’)
> 
> BR,
> Ulf W
> 
> On 30 May 2014, at 21:56, lloyd@REDACTED wrote:
> 
>> Hello,
>> 
>> I'm cross-eyed from looking at match specifications. All I want to do is list all records in my small dets table. I once ran across a very neat query to accomplish that, but for the life can't Google it up.
>> 
>> Can some kind soul give me a query that works?
>> 
>> Many thanks,
>> 
>> LRP 
>> 
>> 
>> 
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
> 
> Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
> http://feuerlabs.com
> 
> 
> 
> 
> 

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list