如何检测mnesia模式和表是否已经在代码中创建?

发布于 2025-01-03 16:09:41 字数 97 浏览 3 评论 0原文

我想在系统启动后在代码中创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

救星 2025-01-10 16:09:41

处理此问题的一种方法是 -

  1. 尝试使用 mnesia:create_table(Table_name, ...) 创建表

  2. 如果表已经存在 (1) 将返回 {aborted,
    {already_exists, Table_name}}

  3. 如果表不存在,则会创建该表并执行 {atomic,ok}
    如果成功则返回

  4. 如果(3)中建表有错误,{aborted, Reason}

根据需要处理每个返回值。

One way to handle this is -

  1. Try creating table using mnesia:create_table(Table_name, ...)

  2. If the table already exists (1) would return {aborted,
    {already_exists, Table_name}}

  3. If table doesn't exit, it will be created and {atomic,ok} will be
    returned if successful

  4. If there is any error in table creation in (3), {aborted, Reason}
    will be returned.

Handle each of these return values as required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文