[erlang-questions] QLC question
Chris Hicks
silent_vendetta@REDACTED
Mon May 2 21:50:17 CEST 2011
I've got a record nested within a record like this:
{account_wrapper, "Username", {account_data, ...}}
And what I want to do is use QLC to search that inner record and see if someone already has chosen a nickname for an account during registration. However, since I've never used QLC before I wanted to start out slow and just get a feel, creating more complex QLC's as I went along until I got where I wanted to go. First I tried this:
mnesia:activity(transaction, fun() -> qlc:eval(qlc:q([{A, B, C} || Wrapper <- mnesia:table(accounts), {A, B, C} <- Wrapper])) end, []).
I just wanted to make sure I understood how to unpack data structures...however I keep getting a qlc error:
** exception exit: {aborted,{badarg,[{qlc,eval, [{error,qlc, {1,qlc,{used_generator_variable,'Wrapper'}}}, []]}, {mnesia_tm,apply_fun,3}, {mnesia_tm,execute_transaction,5}, {mnesia,wrap_trans,6}, {erl_eval,do_apply,5}, {shell,exprs,7}, {shell,eval_exprs,7}, {shell,eval_loop,3}]}} in function mnesia:wrap_trans/6
Now from everything I've read...I thought I'd be able to use the Wrapper variable later on in the query as a generator...thus allowing me to unpack things. Why would this be giving me an error? If I change it to:
mnesia:activity(transaction, fun() -> qlc:eval(qlc:q([{A, B, C} || {A, B, C} <- mnesia:table(accounts)])) end, []).
It works just fine and returns the record...and I can successfully match the pattern {A, B, C} with the account_wrapper record elsewhere. So what am I missing?
Chris Hicks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110502/320c389c/attachment.htm>
More information about the erlang-questions
mailing list