1

我在我的数据库 mnesia 中有两个具有以下语法的表:

-record(person, {firstname, lastname,adress}).
-record(personBackup, {firstname, lastname,adress}).

我想将数据从表person传输到表personBackup

我认为我应该用这种语法创建两个表(我同意你的想法)

mnesia:create_table(person,
   [{disc_copies, [node()]},
    {attributes, record_info(fields, person)}]),
mnesia:create_table(person_backup,
   [{disc_copies, [node()]},
    {attributes, record_info(fields, person)},
    {record_name, person}]),

现在我有一个名为 verify的函数

在这个函数中,我将做一个测试,如果测试得到验证,我应该将数据从person传输到person_backup,然后我应该重置

这是我的功能

verify(Form)->

if Form =:= 40 ->

%%here I should transert data from person to person_backup  : read all lines from person and write this lines into person_backup

reset();

Form =/= 40 ->
io:format("it is ok")
end.

这是功能重置

reset() ->
    stop(),
    destroy(),
    create(),
    start(),
    {ok}.
4

2 回答 2

0

You don't have to use a separate record definition for each table. mnesia:create_table takes a record_name option, so you could create your tables like this:

mnesia:create_table(person,
   [{disc_copies, [node()]},
    {attributes, record_info(fields, person)}]),
mnesia:create_table(person_backup,
   [{disc_copies, [node()]},
    {attributes, record_info(fields, person)},
    {record_name, person}]),

The value for record_name defaults to the name of the table, so there's no need to specify it for person. (I changed personBackup to person_backup, as Erlang atoms are usually written without camel case, unlike variables.)

Then you can put the same kind of records in both tables. Read or select from person, and write to person_backup, no conversion necessary.

于 2013-02-12T14:07:28.073 回答
0

不需要为每个表单独定义记录。变量 90 和 80 可以解决问题。如果你想选择recod_name,你可以使用mnesia:create_table

@legoscia,除了第6行之外,您对所有内容都是正确的。

mnesia:create_table(person, if player value = 1

这样,结果可以光盘所有副本和节点。

于 2013-02-12T16:50:46.123 回答