Erlang从Mnesia开始,写出问题

时间:2013-05-24 12:34:19

标签: erlang mnesia

我在Mnesia数据库中插入数据时遇到了一些问题。

这是代码:(架构已经存在)

-module(mnesia_test).

-record(messages_queue, {id, ack, order, message}).

-export([start/0, add/0]).

start() ->
    mnesia:start(),
    mnesia:delete_table(messages_queue),
    mnesia:create_table(messages_queue, [{attributes, record_info(fields, messages_queue)}, {type, bag}, {record_name, messages_queue}]).

add() ->
    M = #messages_queue{id = "11223344", ack = [0, 5, 32, 91, 23, 106], order= 0, message="Hello world !"},
    mnesia:write(M).

写入get已中止:

Erlang R16B (erts-5.10.1) [source] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.1  (abort with ^G)
1> mnesia_test:start().
{atomic,ok}
2> mnesia_test:add().
** exception exit: {aborted,no_transaction}
     in function  mnesia:abort/1 (mnesia.erl, line 309)

1 个答案:

答案 0 :(得分:0)

我明白了......

写入必须包含在mnesia:transaction()