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

lloyd@REDACTED lloyd@REDACTED
Fri May 30 22:59:43 CEST 2014


Thanks, Garrett.

I stumbled on it as noted in my post to Ulf a moment ago.

So much to keep in mind.

All the best,

L.

-----Original Message-----
From: "Garrett Smith" <g@REDACTED>
Sent: Friday, May 30, 2014 4:56pm
To: "Lloyd Prentice" <lloyd@REDACTED>
Cc: "Ulf Wiger" <ulf@REDACTED>, "erlang questions" <erlang-questions@REDACTED>
Subject: Re: [erlang-questions] How to return all records in dets

Llyod, your first error -- the call to tab2list -- is foobaring the
dets file reference. The dets process is linked to the shell process
on open_file, so when the shell process crashes as a result of this
call to tab2list, every call after that will raise bad argument.

The trick here is to *never* make a mistake in the shell :)

(Just re-open the table and the subsequent calls will work)

On Fri, May 30, 2014 at 3:46 PM,  <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
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list