mnesia table: mnemosyne query

Emmanuelle Bernard <>
Wed Oct 27 22:45:12 CEST 1999


Hi!

I've the following code:

in the file: projet.hrl

-record (domaine, { nom, ip , type }).

in the file: projet.erl

-module(projet).
-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
-export([ nouv_table/1 , insert_ordi/2  ,  essai/0]).

-include("projet.hrl").
-include_lib("mnemosyne/include/mnemosyne.hrl").

nouv_table(Nom_Table) ->
 mnesia:create_table(Nom_Table,[{record_name,domaine},{disc_copies,
[node()]}, {attributes, record_info(fields, domaine)}]).


insert_ordi(Tuple,Where) ->
 Fun = fun() ->
  mnesia:write(Where,Tuple,write)
 end,
 mnesia:transaction(Fun).


essai() ->
Handle=
 query
   [U.ip || U <- table(domaine),
    U.nom = 4]
 end,
Answer =
 mnesia:transaction(
 fun() ->
  mnemosyne:eval(Handle)
 end)
.



In the shell:


21> c(projet).
{ok,projet}

22> projet:nouv_table(ecole).
{atomic,ok}

23> projet:insert_ordi({domaine,4,5,6},ecole).
{atomic,ok}

24>tv:start().
<0.129.0>

25>projet:essai().
{aborted,{no_exists,domaine}}

// if I replace by "U <- table(ecole)" in the projet.erl file
it doesn't want to compile:

    26> c(projet).
    ./projet.erl:112: the record "ecole" is undefined
    ./projet.erl:124: function essai/0 undefined
    error


How can I ask it to search in the table "ecole" (that has a "domaine"
record) with the mnemosyne query?
Moreover, when I check my tables with tv, they are empty, even if I've
written anything in.

Can anyone help me?
thanks

Emmanuelle





More information about the erlang-questions mailing list