Defining records at runtime

tty <>
Wed Apr 5 20:47:53 CEST 2006


Hello folks,

Is there a way of defining records at runtime which usable by QLC ? I currently allow the user to define mnesia tables on the fly. e.g:

     new_table(Table, Attrs) ->
         mnesia:create_table(Table, [... {attributes, Attrs}]).

     new_entry(Table, Vals) ->
         Record = list_to_tuple([Table] ++ Vals),
         mnesia:dirty_write(Record).

However while doing a query I can not write:

     query(Table, Attr, MatchVal) ->
         QH = qlc:q([P || P <- mnesia:table(Table), P#Table.Attr == MatchVal]),
         ...

since the Table record does not actually exist. I get around that by finding the
index of Attr and doing 'elements(Index, P) == MatchVal' instead. It would simplify my code if I could define records at runtime and avoid having to keep track of the location of a particular attribute.

Any ideas ?

Thanks

t



More information about the erlang-questions mailing list