How to implement dynamic queries for MNesia?

I am trying to implement a function that generates dynamic queries for MNesia.

For example, when a function is called with these arguments,

dyn_query(list, person, [name, age], ["jack", 21])

I want to ask MNesia for a list whose name is “jack” and age is 21 people. > table.

I tried to implement this with qlc: q (ListComprehension) and qlc: string_to_handle ("ListComprehension"). At first it failed due to compilation errors, the compiler did not allow me to use functions instead of ListComprehentions and variables instead of record names, such as "Item # Table.Field". The second failed because erl_eval was unable to process the entries and selected exceptions such as {undefined_record, person}.

Which method to use? How can I solve these problems? Or should I use a different method?

Thank.

+3
source share
2 answers

Check the conformance specifications that mnesia: select / 1 uses for table queries. There is mnesia: table_info / 2 for defining the column names (and column indices) of a table.

Matchspecs ERTS . ets: fun2ms/1, , matchspec , erlang, . .

+1

Source: https://habr.com/ru/post/1749540/


All Articles