mnesia question

Ulf Wiger <>
Sat Jul 24 12:10:15 CEST 2004


On Wed, 21 Jul 2004 19:58:14 -0400, Mark Scandariato <> 
wrote:

> Are the table property functions (mnesia:read_table_property/2, et al) 
> intended for general use? They're not mentioned in the docs - except 
> that 'user_properties' is mentioned in the description of 
> mnesia:table_info/2.

Hadn't noticed that they're undocumented, but 'rdbms' (at Jungerl)
makes extensive use of table properties.

There are also some (undocumented) functions in mnesia_schema.erl
that make it possible to create/modify user properties more flexibly
within a schema transaction:

 From 
http://cvs.sourceforge.net/viewcvs.py/jungerl/jungerl/lib/rdbms/src/rdbms.erl?rev=1.2&view=auto


drop_references(ToTab) ->
     mnesia_schema:schema_transaction(
       fun() ->
               do_drop_references(ToTab)
       end).

do_drop_references(ToTab) ->
     lists:foreach(
       fun(Tab) ->
               Props = mnesia:table_info(Tab, user_properties),
               search_props(Props, ToTab, Tab)
       end, mnesia:system_info(tables)).

search_props([{{attr,Attr,references},Refs}|Props], ToTab, Tab) ->
     case [{T,A,As} || {T,A,As} <- Refs,
                       T == ToTab] of
        [] ->
            %% no reference to ToTab
            search_props(Props, ToTab, Tab);
        Remove ->
            do_set_property({attr,{Tab,Attr},references}, Refs -- Remove),
            search_props(Props, ToTab, Tab)
     end;
search_props([P|Ps], ToTab, Tab) ->
     search_props(Ps, ToTab, Tab);
search_props([], _, _) ->
     ok.

... % do_set_property eventually calls do_write_property/2

do_write_property(Tab, Prop) ->
     mnesia_schema:do_write_table_property(Tab, Prop).

Regards,
Uffe
-- 
Ulf Wiger




More information about the erlang-questions mailing list