mnesia table: mnemosyne query

Ulf Wiger etxuwig@REDACTED
Thu Oct 28 10:17:13 CEST 1999


Emmanuelle,

You can try writing like this for now:

essai() ->
   {atomic, Objs} =
      mnesia:transaction(
         fun() ->
            mnesia:match_object(ecole, '_')
         end),
   [D#domaine.id || D <- Objs, D#domain.nom == 4].

For simple queries, this is just as efficient as mnemosyne.

Also, for checking your tables quickly, you may try ets:tab2list(ecole) or
ets:i(), since disc_copies are also stored in RAM, at ETS tables.

There is also an Open Source contribution called trex, similar to tv, which
doesn't have a problem displaying tables, even if the records differ.

/Uffe


On Wed, 27 Oct 1999, Emmanuelle Bernard wrote:

eberna>Hi!
eberna>
eberna>I've the following code:
eberna>
eberna>in the file: projet.hrl
eberna>
eberna>-record (domaine, { nom, ip , type }).
eberna>
eberna>in the file: projet.erl
eberna>
eberna>-module(projet).
eberna>-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
eberna>-export([ nouv_table/1 , insert_ordi/2  ,  essai/0]).
eberna>
eberna>-include("projet.hrl").
eberna>-include_lib("mnemosyne/include/mnemosyne.hrl").
eberna>
eberna>nouv_table(Nom_Table) ->
eberna> mnesia:create_table(Nom_Table,[{record_name,domaine},{disc_copies,
eberna>[node()]}, {attributes, record_info(fields, domaine)}]).
eberna>
eberna>
eberna>insert_ordi(Tuple,Where) ->
eberna> Fun = fun() ->
eberna>  mnesia:write(Where,Tuple,write)
eberna> end,
eberna> mnesia:transaction(Fun).
eberna>
eberna>
eberna>essai() ->
eberna>Handle=
eberna> query
eberna>   [U.ip || U <- table(domaine),
eberna>    U.nom = 4]
eberna> end,
eberna>Answer =
eberna> mnesia:transaction(
eberna> fun() ->
eberna>  mnemosyne:eval(Handle)
eberna> end)
eberna>.
eberna>
eberna>
eberna>
eberna>In the shell:
eberna>
eberna>
eberna>21> c(projet).
eberna>{ok,projet}
eberna>
eberna>22> projet:nouv_table(ecole).
eberna>{atomic,ok}
eberna>
eberna>23> projet:insert_ordi({domaine,4,5,6},ecole).
eberna>{atomic,ok}
eberna>
eberna>24>tv:start().
eberna><0.129.0>
eberna>
eberna>25>projet:essai().
eberna>{aborted,{no_exists,domaine}}
eberna>
eberna>// if I replace by "U <- table(ecole)" in the projet.erl file
eberna>it doesn't want to compile:
eberna>
eberna>    26> c(projet).
eberna>    ./projet.erl:112: the record "ecole" is undefined
eberna>    ./projet.erl:124: function essai/0 undefined
eberna>    error
eberna>
eberna>
eberna>How can I ask it to search in the table "ecole" (that has a "domaine"
eberna>record) with the mnemosyne query?
eberna>Moreover, when I check my tables with tv, they are empty, even if I've
eberna>written anything in.
eberna>
eberna>Can anyone help me?
eberna>thanks
eberna>
eberna>Emmanuelle
eberna>
eberna>
eberna>

Ulf Wiger, Chief Designer AXD 301         <ulf.wiger@REDACTED>
Ericsson Telecom AB                          tfn: +46  8 719 81 95
Varuvägen 9, Älvsjö                          mob: +46 70 519 81 95
S-126 25 Stockholm, Sweden                   fax: +46  8 719 43 44




More information about the erlang-questions mailing list