Create table in a transaction

Ulf Wiger etxuwig@REDACTED
Fri Nov 3 09:52:44 CET 2000


On Thu, 2 Nov 2000, Dan Gudmundsson wrote:

>
>Sorry, but you can't do schema_transactions inside a normal transaction.
>
>schema_transaction's include 
>create_table
>move_table_copy
>add_table_copy
>change_table_copy
>del_table
>transform_table
>..
>
>I got some requests on this but it is a lot of work do it rigth
>with current implementation..
>
>/Dan

But wouldn't it be possible to perform normal table updates from
within a schema transaction?

I haven't followed the complete thread, but it does seem as if
schema_transaction calls mnesia:transaction/1, and that mnesia_tm.erl
doesn't really care if schema transactions are combined with other
operations.

My mnesia_schema patch in the rdbms contrib exports
mnesia_schema:schema_transaction/1, and has a few hacks to support
multiple calls to write_table_property/2 within one schema
transaction. You could try calling normal table ops within
schema_transaction and see what happens.

Note, though, that schema_transaction can't be called from within a
transaction. If you want to try this, you'd also have to call
create_table a bit differently. Here's an example from some code I've
written:

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).




/Uffe


>Chandrashekhar Mullaparthi writes:
> > 
> > I can't create a table within a transaction. Why is that?? A comment in
> > mnesia_schema.erl says that a "very special transaction is used when we want
> > to manipulate the schema". Basically what I want to do is:
> > 
> > * Do some checks
> > * Update table_1
> > * create table_2
> > * Make entries in table_2
> > 
> > in one single transaction. I'm failing at step 3.
> > 
> > tia,
> > Chandru
> > 
>

-- 
Ulf Wiger                                    tfn: +46  8 719 81 95
Senior System Architect                      mob: +46 70 519 81 95
Strategic Product & System Management    ATM Multiservice Networks
Data Backbone & Optical Services Division      Ericsson Telecom AB




More information about the erlang-questions mailing list