Erlang/OTP Forums

Author Message

<  Erlang  ~  How do you write an mnesia update query?

LRP
Posted: Mon Oct 13, 2008 3:04 am Reply with quote
Joined: 08 Oct 2008 Posts: 8 Location: Boston, MA.
Hello,

At risk of sounding desperate (fast getting there), I'm rephrasing the question I posted on October 8.

Suppose I have the following record structure:

-record(news,
{newsID,
head,
copy,
dateline}).

...where head and copy are binaries. How do I write a mnesia query to update the head and/or copy fields?

Table is initialized as follows:

init_newswire() ->
% Initialize database
mnesia:create_schema([node()]),
mnesia:start(),
try
mnesia:table_info(news, type)
catch
exit: _ ->
mnesia:create_table(news, [
{attributes, record_info(fields, news)},
{type, set},
{disc_copies, [node()] }
])
end.


Seems to me that every good erlang programmer would know how to do this, but there were no responses to my post and I come up blank in my Google searches.

Many thanks,

LRP
View user's profile Send private message
klaar
Posted: Wed Oct 15, 2008 10:18 pm Reply with quote
User Joined: 06 Oct 2008 Posts: 11 Location: Göteborg/Sweden
It depends upon which type of table that is used. If you are using (set|ordered_set) then just write it again, just like you did the first time. The old version will be overwritten, so make sure that you have read out _all_ of the data before you do this Smile

http://www.erlang.org/doc/apps/mnesia/index.html
View user's profile Send private message
LRP
Posted: Wed Oct 15, 2008 10:28 pm Reply with quote
Joined: 08 Oct 2008 Posts: 8 Location: Boston, MA.
Many thanks.

I did scour the menesia reference manual. But must have missed... or misunderstood how to update records.

Thanks again,

LRP
View user's profile Send private message
Mazen
Posted: Thu Oct 16, 2008 7:30 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
My excuse:

The word "query" threw me off...

Very Happy
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

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 cannot attach files in this forum
You cannot download files in this forum