如何检测mnesia模式和表是否已经在代码中创建?
我想在系统启动后在代码中创建 mnesia 模式和表,因此我需要检测 mnesia 模式和表是否已创建。如果没有,我想创建它们。这是个好主意吗?我如何检测 mnesia 模式和表?
I want to create an mnesia schema and table in my code after the system starts, so I need to detect weather the mnesia schema and table have been created. If not, I want to create them. Is this a good idea? And how can I detect the mnesia schema and table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理此问题的一种方法是 -
尝试使用
mnesia:create_table(Table_name, ...) 创建表
如果表已经存在 (1) 将返回
{aborted,
{already_exists, Table_name}}
如果表不存在,则会创建该表并执行
{atomic,ok}
如果成功则返回
如果(3)中建表有错误,
{aborted, Reason}
根据需要处理每个返回值。
One way to handle this is -
Try creating table using
mnesia:create_table(Table_name, ...)
If the table already exists (1) would return
{aborted,
{already_exists, Table_name}}
If table doesn't exit, it will be created and
{atomic,ok}
will bereturned if successful
If there is any error in table creation in (3),
{aborted, Reason}
will be returned.
Handle each of these return values as required.
查看
mnesia:system_info/1
,mnesia:schema/0
,mnesia:schema/1
和mnesia:table_info/2
。check out
mnesia:system_info/1
,mnesia:schema/0
,mnesia:schema/1
andmnesia:table_info/2
.