Dynamic Mnesia Queries.

Elan icimjs@REDACTED
Fri Jun 18 08:43:22 CEST 1999


Hi everyone,

first of all, thank you all for the useful responses.

Torbjorn Tornkvist wrote:
>Great ! How did it go ?

We're still waiting for their new computers to arrive, which gives me a
little time to improve my code.

We've decided to use Linux instead of MS Windows :-)

Here's what I'm currently wrestling with:

Right now I have the following "generic" function:

list_glue() ->
  Fun = fun() ->
    Q = query [G.product_name || G <- table(glue)] end,
    mnemosyne:eval(Q)
  end,
  mnesia:transaction(Fun).

Fine.

What I'd like to do is something like this (which doesn't work):

list_generic(Table, Tuple, Condition) ->
  Fun = fun() ->
    Q = query( Tuple || ??? <- table(Table),
      Condition ] end,
    mnemosyne:eval(Q)
  end,
  mnesia:transaction(Fun).

Then I would want to be able to call it with something like this ... from
the shell

list_generic(glue, 
   {glue, Product_Name, _ , _ , _ ,},  
   {glue, _ , _ , _ , "Some glue manufacturer here"} ).

where the record is
-record(glue, {name, id, reference, manufacturer}).

in order to get all glue products this particular manufacturer carries. On
a different occasion I want to use the same function list_generic, to
identify the type of glue I need to use for a certain type of floor
covering, something like this

list_generic(linoleum,
  {linoleum, Glue_ID, _ , _ },
  {linoleum, _ , "00134", _ } ).

where the record is
-record(linoleum, {glue_reference, linoleum_id, manufacturer}).

How could something like this be implemented? Is it at all possible? Will I
need to use 
record_info(fields, Rec) -> [Names].

in the list_generic/3 function in order to construct a record and assign
the values from the tuples Tuple and Condition to the record? How do I do
that dynamically, i.e. during runtime?

I think I'm close to the solution, but I'm still struggling with the
documentation  to get it right.

Is there a better way to achieve the same effect?

TIA,

Elan

====================================
Get your copy of FaxForward
http://www.commercebox.com/FaxForward/




More information about the erlang-questions mailing list