Erlang从Mnesia开始,写出问题(Erlang starting with Mnesia, write Issues)
我在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).写入获取中止:
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)I'm having some issue inserting data in a Mnesia database.
Here's the code : (schema already exists)
-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).The write get's aborted :
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)最满意答案
我知道了...
写入必须包含在mnesia:transaction()中
I got it...
The write must be wrapped in a mnesia:transaction()
更多推荐
发布评论