Mnemosyne query by a partial key
Dan Gudmundsson
dgud@REDACTED
Wed Jan 22 16:20:56 CET 2003
{aborted,mnemosyne_not_running}
means that you forgot to start the application mnemosyne,
i.e. use application:start(mnemosyne). before any mnemosyne queries.
But the select call is the preferred way..
Though you forgot to bind the $2 in your select expr.
/Dan
PS: Yes I know I got a bug in select, a bad match-spec will loop
the transaction forever :-(, will be corrected in next patch.
In the mean time use ets:test_ms/2 to check your match_spec.
Carlos Silva writes:
> Hi everybody.
>
> I'd like to know if it is possible to include a function call in the body of a Mnemosyne query. Knowing that a query is declared as: query [ <pattern> || <body> ] end
>
> The doubt comes to me when I tried to run this example:
> Q = query [{E.item, E.url} || E <- table(menus), element(1, E.item) = Level] end,
>
> but a "{aborted,mnemosyne_not_running}" is all I've obtained from the shell :o(
>
> Neither I could run my example in this way:
> ...
> Menus = #menus{item = '$1'},
> Guard = {'==','element(1, $1)',Level},
> mnesia:select(menus, [{Menus , [Guard], [['$1','$2']]}])
> ...
>
> I'd be happy if someone could tell me how to execute a query by a partial key, when the key of a Mnesia table is a compound key as {elem1, elem2, elem3} and I want to search only by elem1 for example.
>
> Thanks a lot,
>
> Ing. Carlos E. Silva
> INSwitch Solutions
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
> <META content="MSHTML 5.00.2920.0" name=GENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=#ffffff>
> <DIV><FONT face=Arial size=2>Hi everybody.</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>I'd like to know if it is possible to include a
> function call in the body of a Mnemosyne query. Knowing that a query is declared
> as</FONT><FONT face=Arial size=2>: query [ <pattern> || <body> ]
> end</FONT></DIV>
> <DIV> </DIV>
> <DIV><FONT face=Arial size=2>The doubt comes to me when I tried to run this
> example:</FONT></DIV>
> <DIV><FONT face=Arial
> size=2> Q = query
> [{E.item, E.url} || E <- table(menus), <STRONG>element(1, E.item) </STRONG>=
> Level] end,</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>but a "{aborted,mnemosyne_not_running}" is all I've
> obtained from the shell :o(</FONT></DIV>
> <DIV> </DIV>
> <DIV><FONT face=Arial size=2>Neither I could run my example in this
> way:</FONT></DIV>
> <DIV><FONT face=Arial size=2>...</FONT></DIV>
> <DIV><FONT face=Arial size=2> Menus = #menus{item =
> '$1'},</FONT></DIV>
> <DIV><FONT face=Arial size=2> Guard =
> {'==',<STRONG>'element(1, $1)'</STRONG>,Level},<BR>
> mnesia:select(menus, [{Menus , [Guard], [['$1','$2']]}])</FONT></DIV>
> <DIV><FONT face=Arial size=2>...</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>I'd be happy if someone could tell me how to
> execute a query by a partial key, when the key of a Mnesia table is a compound
> key as {elem1, elem2, elem3} and I want to search only by elem1 for
> example.</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>Thanks a lot,</FONT></DIV>
> <DIV><FONT face=Arial size=2></FONT> </DIV>
> <DIV><FONT face=Arial size=2>Ing. Carlos E. Silva</FONT></DIV>
> <DIV><FONT face=Arial size=2>INSwitch Solutions</FONT><FONT face=Arial
> size=2></DIV></FONT></BODY></HTML>
--
Dan Gudmundsson Project: Mnesia, Erlang/OTP
Ericsson Utvecklings AB Phone: +46 8 727 5762
UAB/F/P Mobile: +46 70 519 9469
S-125 25 Stockholm Visit addr: Armborstv 1
More information about the erlang-questions
mailing list