filtering functions in mnemosyne

Laszlo Varga Laszlo.Varga@REDACTED
Wed Nov 28 17:17:45 CET 2001


Hi Sirs,

sorry for this newby question. I'm just playing around with mnesia,
and has found something which shurely possible but I couldn't get through.

What I want, is to use a function in a query like this (simplified)
    
isTheSame({A,A}) -> true;
isTheSame(B) -> false.  

for cheking the records.

What I get: 
{aborted,{badarg,{ets,lookup,[db_get,[mnemosyne_catalog,{image,foo}]]}}}

I have a simple record

-record(foo,{this,that}).

some simple functions:

-module(trial).
-include_lib("mnemosyne/include/mnemosyne.hrl").
-include("trial.hrl").
-export([find1/1,find2/1,init/0,isTheSame/1]).


add({This,That})->
    Fun = fun() ->
          NetRecord = #foo{this = This, that =That},                            
          mnesia:write(NetRecord)
          end,
   mnesia:transaction(Fun).




init() ->
    mnesia:create_table(foo , [{attributes,record_info(fields,foo)}]),
    add({1, 2}),
    add({2, 2}),
    add({3, 3}).
    
    
isTheSame({A,A}) -> true;
isTheSame(B) -> false.    
    
find1(Table)->
    F = fun() ->
        Q = query [E || E <- table(Table),
                          E.this = E.that] 
        end,
        mnemosyne:eval(Q)
    end,
    mnesia:transaction(F).

    
find2(Table)->
    F = fun() ->
        Q = query [E || E <- table(Table),
                          isTheSame({E.this,E.that})] 
        end,
        mnemosyne:eval(Q)
    end,
    mnesia:transaction(F).    
    
    
    
find1 works properly
 trial:find1(foo).
{atomic,[{foo,2,2},{foo,3,3}]}

find2 gives 
trial:find2(foo).
{aborted,{badarg,{ets,lookup,[db_get,[mnemosyne_catalog,{image,foo}]]}}}



How to do things like this?

(I 'm using old 4.3.7 erlang)

Thanks
Laszlo Varga

mailto: ethvala@REDACTED




More information about the erlang-questions mailing list