Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  Mnesia - is thera generic way to show a tables content ?

brett hallett
Posted: Mon Aug 27, 2007 12:22 am Reply with quote
User Joined: 21 Aug 2007 Posts: 21
I'm working my way thru the Mnesia manual, and cant figure out if there is a generic way to list a tables content.

The examples are very specific in that they select
a particular record(s) eg: the 'all-Females' example.

What I want is to be able to simply list off all records (and fields)
in a particular table using the least complex 'query',


The equivalent of SQL's "Select * from tablename", and NO I'm not wanting to use SQl Laughing
View user's profile Send private message
michal
Posted: Mon Aug 27, 2007 7:42 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 44 Location: London
Hi,
You can get all the keys of some table using mnesia:dirty_all_keys/1 function ( http://www.erlang.org/doc/man/mnesia.html#dirty_all_keys/1 ). If you want to get not only the keys but also whole records you can call mnesia:dirty_read/2 for each key. Combining the above two functions in a list comprehension could look like this:

[mnesia:dirty_read(TableName, Key) || Key <- mnesia:dirty_all_keys(TableName)].

If you work in Erlang shell, you have mnesia running and you simply want to print out all the records you can use:

ets:tab2list(TableName).

Michal

_________________
http://www.erlang-consulting.com
View user's profile Send private message
brett hallett
Posted: Mon Aug 27, 2007 11:45 pm Reply with quote
User Joined: 21 Aug 2007 Posts: 21
Thanks , thats exactly what I need.
View user's profile Send private message
khigia
Posted: Tue Aug 28, 2007 8:47 am Reply with quote
User Joined: 27 Mar 2007 Posts: 52
I often use the tv module to inspect ETS or Mnesia tables.
Code:
(erlnode@erlhost)1> tv:start().
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum