Select 复杂记忆中的一个值 table
Select a value in complex mnesia table
我是 Erlang 和 Mnesia 的新手。我在 mnesia 中创建了一个 table:
-record(user, {name="", game=""}).
-record(base, {user=#user{}, score=0}).
init() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(base, [{attributes, record_info(fields, base)}]),
mnesia:stop().
现在我想 select table 基数的所有行,其中 "game" 是某个值。我写了这个函数,但是当游戏变量不等于“”时它不起作用。
exec(base, Game) when is_list(Game)->
F = fun() ->
if
Game =/= "" ->
Q = qlc:q([{R#base.user#user.name, R#base.score} || R <- mnesia:table(base), R#base.user#user.game == Game]);
true ->
Q = qlc:q([{R#base.user, R#base.score} || R <- mnesia:table(base)])
end,
qlc:e(Q)
end,
{_, Data} = mnesia:transaction(F),
Data;
我怎样才能查询到它?
已解决。我改变了我的功能:
exec(base, Game) when is_list(Game)->
F = fun() ->
if
Game =/= "" ->
Q = qlc:q([{Name, Score} || #base{user={Name, G}, score=Score} <- mnesia:table(base), G == Game]);
true ->
Q = qlc:q([{R#base.user, R#base.score} || R <- mnesia:table(base)])
end,
qlc:e(Q)
end,
{_, Data} = mnesia:transaction(F),
Data;
我是 Erlang 和 Mnesia 的新手。我在 mnesia 中创建了一个 table:
-record(user, {name="", game=""}).
-record(base, {user=#user{}, score=0}).
init() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(base, [{attributes, record_info(fields, base)}]),
mnesia:stop().
现在我想 select table 基数的所有行,其中 "game" 是某个值。我写了这个函数,但是当游戏变量不等于“”时它不起作用。
exec(base, Game) when is_list(Game)->
F = fun() ->
if
Game =/= "" ->
Q = qlc:q([{R#base.user#user.name, R#base.score} || R <- mnesia:table(base), R#base.user#user.game == Game]);
true ->
Q = qlc:q([{R#base.user, R#base.score} || R <- mnesia:table(base)])
end,
qlc:e(Q)
end,
{_, Data} = mnesia:transaction(F),
Data;
我怎样才能查询到它?
已解决。我改变了我的功能:
exec(base, Game) when is_list(Game)->
F = fun() ->
if
Game =/= "" ->
Q = qlc:q([{Name, Score} || #base{user={Name, G}, score=Score} <- mnesia:table(base), G == Game]);
true ->
Q = qlc:q([{R#base.user, R#base.score} || R <- mnesia:table(base)])
end,
qlc:e(Q)
end,
{_, Data} = mnesia:transaction(F),
Data;