Mnesia schema transaction

Ulf Wiger <>
Thu Mar 4 13:17:23 CET 2004


Hi Rudolph,

You can use nmesia_schema:do_create_table/1 (which also
requires use of mnesia_schema:list2cs/1.)

Here's some sample code from one of my unfinished contribs:


initialise_class(Class) ->
     {Attrs, TableProps, UserProps} = Class:describe(),
     F = fun() ->
                 create_table(Class, table_properties(Attrs, TableProps)),
                 rdbms:do_add_properties(UserProps, Class)
         end,
     mnesia_schema:schema_transaction(F).


create_table(Name, Properties) ->
     Cs = mnesia_schema:list2cs([{name, Name}|Properties]),
     mnesia_schema:do_create_table(Cs).

table_properties(Attrs, Opts) ->
     Nodes = mnesia:system_info(db_nodes),
     RemoveKeys = [disc_copies, ram_copies, disc_copies],
     Rest = [{K,V} || {K,V} <- Opts,
                      not(lists:member(K, RemoveKeys))],
     [{attributes, Attrs},
      {disc_only_copies, opt(disc_only_copies, Opts,  Nodes)},
      {ram_copies, opt(ram_copies, Opts,  [])},
      {disc_copies, opt(ram_copies, Opts,  [])}|Rest].

/Uffe

On Thu, 4 Mar 2004 12:50:55 +0100, Rudolph van Graan 
<> wrote:

> Hi all,
>
> Previously Ulf Wiger posted about
> mnesia_schema:schema_transaction(fun() -> ...)
>
> This function is exported and usuable, however inside mnesia_schema, I
> found this code:
>
> create_table(TabDef) ->
>      schema_transaction(fun() -> do_multi_create_table(TabDef) end).
>
> Now, if I do create_table inside a schema_transaction, it aborts with
> "nested transaction" - obviously because the above call already runs it
> as a transaction. Now, there seems to be no other create_table function
> that I can use to achieve transactions here that I could find. Is it
> really necessary to update mnesia's code to get create_table to run
> inside a transaction or am I again missing the obvious?
>
> Thank you in advance,
>
>
> Rudolph van Graan



-- 
Ulf Wiger, Senior System Architect
EAB/UPD/S

This communication is confidential and intended solely for the addressee(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you believe this message has been sent to you in error, please notify the sender by replying to this transmission and delete the message without disclosing it. Thank you.

E-mail including attachments is susceptible to data corruption, interruption, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.




More information about the erlang-questions mailing list