mnemosyne-bug?

Ulf Wiger etxuwig@REDACTED
Wed Jun 18 11:56:41 CEST 2003


I did intend to illustrate the problem below some more, but
ran into another mnemosyne bug.

12> mnemosyne:string_to_handle("query [X || X <- table(foo)] end. ").
{'EXIT',{function_clause,[{erl_parse,normalise,
                                     [{call,
                                          0,
                                          {atom,0,'MNEMOSYNE RULE'},
                                          [{tuple,
                                               0,
                                               [{atom,0,data},
                                                {atom,0,record_defs}]}]}]},
                          {erl_parse,normalise_list,1},
                          {erl_parse,normalise,1},
                          {erl_parse,normalise_list,1},
                          {erl_parse,normalise,1},

{mnemosyne_lc,'-one_lc_to_handle/1-fun-1-',2},
                          {lists,foldl,3},
                          {mnemosyne_lc,one_lc_to_handle,1}|
                          more]}}


Writing a module that includes some queries does work, so I
wrote the following:

-module(mnemtest).

-compile(export_all).

-include_lib("mnemosyne/include/mnemosyne.hrl").

-record(foo, {a1,a2,a3}).
-record(bar, {a1,a2,a3}).

foo() ->
    Q = query
	    [X || X <- table(foo)]
	end,
    mnesia:transaction(
      fun() ->
	      mnemosyne:eval(Q)
      end).

bar() ->
    Q = query
	    [X || X <- table(bar)]
	end,
    mnesia:transaction(
      fun() ->
	      mnemosyne:eval(Q)
      end).


Recalling that the table foo was created as:

>3> mnesia:create_table(foo,[{attributes,[a1,a2,a3]},{record_name,rec}]).

the record definition -record(foo, [a1,a2,a3]) is
irrelevant, but mnemosyne will not compile the function
foo() without it.

I also created a table bar such that:

4> mnesia:create_table(bar,[{attributes,[a1,a2,a3]}]).
{atomic,ok}
5> mnesia:dirty_write(bar, {bar,1,2,3}).
ok
6> c(mnemtest).
{ok,mnemtest}
7> mnemtest:foo().
{atomic,[]}
8> mnemtest:bar().
{atomic,[{bar,1,2,3}]}
9> ets:tab2list(foo).
[{rec,1,2,3}]
10> ets:tab2list(bar).
[{bar,1,2,3}]

That is, the query in foo() above only compiles if given an
incorrect record definition, and thus doesn't find anything
in the table foo. However, finding all data in 'bar' (which
has the same record name as the table name) works fine.

/Uffe

On Wed, 18 Jun 2003, Ulf Wiger wrote:

>
>Looking at the code in mnemosynce_lc:make_rec_defs/1,
>
>mk_rec_defs(TabAttrs) ->
>  lists:map(fun({Tab,Attrs}) ->
>                  {attribute,0,record,
>                   {Tab, lists:map(fun(Attr) ->
>                                         {record_field,0,{atom,0,Attr}}
>                                   end, Attrs)}}
>            end, TabAttrs).
>
>
>shouldn't it call mnesia:table_info(Tab, record_name)
>instead of naively assuming that the record_name is always
>the same as the table name?
>
>3> mnesia:create_table(foo,[{attributes,[a1,a2,a3]},{record_name,rec}]).
>{atomic,ok}
>4> mnesia:table_info(foo,record_name).
>rec
>5> mnesia:dirty_write(foo, {foo,1,2,3}).
>** exited: {aborted,{bad_type,{foo,1,2,3}}} **
>6> mnesia:dirty_write(foo, {rec,1,2,3}).
>ok
>
>
>/Uffe
>

-- 
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson AB, Connectivity and Control Nodes




More information about the erlang-questions mailing list