Erlang从Mnesia开始,写出问题(Erlang starting with Mnesia, write Issues)

编程入门 行业动态 更新时间:2024-10-25 04:26:11
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()

更多推荐

本文发布于:2023-07-26 00:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268319.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Mnesia   Erlang   starting   Issues   write

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!