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?
How to detect whether the mnesia schema and table have been created in code?
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 be returned if successfulIf there is any error in table creation in (3),
{aborted, Reason}
will be returned.
Handle each of these return values as required.
Before you can create a table you need to create the schema, so I don't see how this solution works. You'd need to catch the error thrown when the schema is created and when
application:start(mnesia)
is called as well. –
Ruel check out mnesia:system_info/1
, mnesia:schema/0
, mnesia:schema/1
and mnesia:table_info/2
.
© 2022 - 2024 — McMap. All rights reserved.
mnesia:info().
in shell will echo many useful things – Volkman