| Author |
Message |
|
| brett hallett |
Posted: Tue Nov 20, 2007 10:36 am |
|
|
|
User
Joined: 21 Aug 2007
Posts: 21
|
I've been experimenting with mnesia's various I/O functions, and when trying a dirty_read,
the returned result list seems overly complex !
dirty_read thus :
M2 =[mnesia:dirty_read(account, Key)
|| Key <- mnesia:dirty_all_keys(account)],
results in : M2
[[{account,"joe",388.280}],[{account,"Max",999}]]
ie: each record tuple {} in a list [] of it own, then each list is inside another list !!
on the other hand if I use QLC , eg:
F = fun() ->
Q = qlc:q([E || E <- mnesia:table(account)]),
qlc:e(Q)
end,
S = mnesia:transaction(F),
{_,Z} = S,
the result is
QLC (S) : {atomic,[{account,"joe",388.280},{account,"Max",999}]}
QLC (Z) : [{account,"joe",388.280},{account,"Max",999}]
So I end up with a single list populated with tuples, a much better LIST result to process,
as now I have all the tuples in one list, as my program is trying to use a common routine
to accumulate the account balances, so I need a consistent list to pass.
How do I process thislist
[[{account,"joe",388.280}],[{account,"Max",999}]]
to achieve this list
[{account,"joe",388.280},{account,"Max",999}]
I've tried a number of the list processing functions without success.
Thanks.
====================================================
{ok,cu}
113> cu:showAccs().
20/11/2007 17:16:02
QLC (S) : {atomic,[{account,"joe",388.280},{account,"Max",999}]}
QLC (Z) : [{account,"joe",388.280},{account,"Max",999}]
print3: account joe 388.28
print3: account Max 999.00
** end accounts list 3 ***
printHdr : [{account,"joe",388.280},{account,"Max",999}]
Account : AccName: Balance:
joe 388.28
Max 999.00
Total : 1387.28
** end accounts list 2 ***
ok
116> cu:accounts().
20/11/2007 17:16:44
dirty_read (M2) : [[{account,"joe",388.280}],[{account,"Max",999}]]
print1: {account,"joe",388.280}
print1: {account,"Max",999}
** end accounts list 1 ***
printHdr : [[{account,"joe",388.280}],[{account,"Max",999}]]
Account : AccName: Balance:
=ERROR REPORT==== 20-Nov-2007::17:16:44 ===
Error in process <0.578.0> with exit value: {{badmatch,[{account,"joe",3.882800e+02}]},[{cu,print2,2},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
** exited: {{badmatch,[{account,"joe",388.280}]},
[{cu,print2,2},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **
118> |
|
|
| Back to top |
|
| Mazen |
Posted: Wed Nov 28, 2007 9:49 am |
|
|
|
User
Joined: 20 Jul 2006
Posts: 164
Location: London
|
Hi Brett!
Try changing:
Code:
M2 =[mnesia:dirty_read(account, Key) ||
Key <- mnesia:dirty_all_keys(account)]
to
Code:
M2 =[hd(mnesia:dirty_read(account, Key)) ||
Key <- mnesia:dirty_all_keys(account)]
This will only work on non-bag tables and will crash if a record is removed from the table while going through it. Also check out dirty_first and dirty_next for iterating over a table.
The reason you get every element wrapped in a list is because the return value of dirty_read is in a list even if it only gets 1 record. |
|
|
| Back to top |
|
| brett hallett |
Posted: Sat Dec 01, 2007 3:33 am |
|
|
|
User
Joined: 21 Aug 2007
Posts: 21
|
Thanks Mazen, for the suggestion -- works a treat !
I note your comments re 'dirty' operations, I'm just trying them because they are there! |
|
|
| Back to top |
|
| wuji |
Posted: Mon Aug 27, 2012 6:54 am |
|
|
|
User
Joined: 10 Aug 2012
Posts: 654
|
manager of the Golden Lamb, the historic restaurant and inn inn cheap authentic jordans inn in Lebanon, Ohio, which has been owned by Portman's
since 1926 — and where Portman usually orders the duck duck cheap designer *beep* duck breast and the lingonberry jus. "I think he would
tremendous at whatever he does."People in Ohio who have grown grown [h2]cheap Ralph Lauren[/h2] grown to know Portman well say that even if he
to become vice president, he wouldn't abandon his roots in in [h2]cheap Ralph Lauren[/h2] in the swing state from which he hails.Portman has forged
relationship with the parents of Matt Maupin, an Army sergeant sergeant cheap polo shirts sergeant from Ohio who was captured in Iraq in 2004,
later killed by insurgents. While Maupin was missing, Portman set set real jordans set up a meeting between President Bush and Maupin's parents,
a |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|