I create a table whose name is NOT the same as its record name. Here below is the code snippet
%% ---- record definition -------------------------------- -record(object,{key,value}).On doing this, mnesia cries out loud with an execption. The table is created very well, and can be viewed in
%% ---- create table ------------------------------------- {atomic,ok} = mnesia:create_table(mytable,[ {type,set}, {frag_properties,[ {node_pool,[node()]}, {n_fragments,4}, {n_disc_copies,1}]}, {attributes,record_info(fields,object)}] ),
%% ------- inserting --------------------------------
insert()-> F = fun() -> R = #object{ key = "MyKey", value = "Value" }, mnesia:write(mytable,R,write) end, mnesia:activity(transaction,F,[],mnesia_frag).
tv:start().
or in mnesia:info().
. This is the error i see on my shell.** exception exit: {aborted, {bad_type, #object{ key = "MyKey", value = "Value"}}} in function mnesia:wrap_trans/6 (mnesia.erl, line 395)Now, normally, i thought that one would get such an error when the record definition used when creating a table is different from the record structure being inserted in the table. I wonder is this is just a problem with the function i am using, that is:
mnesia:write/3
which helps when the table name is different from the record name.I have tried deleting the schema and creating it anew, but all in vain. When i do not use
mnesia:write/3
, the record gets inserted properly in the table. But my application needs are such that i will have several different tables which are created but they store the same record structure/definition. I want to have different tables but their record_info
definition is the same. Somewhere in the docs, i read that this is very possible. I am running:
Erlang otp R15B, mnesia-4.6 , windows 7 enterprise, 32-bit operating system, Dell laptop, intel core i5, 4GB RAM
All other erlang projects i am working on are fine, they have no wierd/unexpected behavior like this one has.Any suggestions ?