[erlang-questions] Mnemosyne query problem

Matej Kosik <>
Fri Jan 11 16:12:21 CET 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Friends,

I would like to perform the following query:

    TableName = circuit,
    AttributeValue = ipe_od,
    AttributeName = type,
    F = fun() ->
         Q = query
            [  Entity
            || Entity <- table(TableName),
               Entity.AttributeName=AttributeValue
            ]
         end,
         mnemosyne:eval(Q)
    end,
    {atomic, Entities} = mnesia:transaction(F).

Unfortunatelly, compilator rejects its. I would like to write a code that selects particular
entities from a given TableName whose AttributeName has a given AttributeValue.

Since Erlang does not accept bound variables here

	Entity.AttributeName=AttributeValue

I must literally hard-wire particular attribute name. For example

	Entity.od_id=AttributeValue

(here `od_id' means id of octal-demodulator). This way I would have to write such code for every
kind of Mnesia table and for every attribute name. That is possible but does not makes sense.

The immediate hack is to load all entities into the memory and make ordinary list-comprehension. It
might work, as long as things fit into memory (and some other things in VM do not overflow). But how
to actually write a code that works as the original (non-compilable) piece was supposed to work?

Thanks in advance
- --
Matej Kosik
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHh4dVL+CaXfJI/hgRAisKAKDXDWxoIbO9WP+jDqO5UQMXJiVLhQCgpklI
iYolHdgQ/8A3dpAfl0FoNak=
=/v97
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list