mnesia:transform_table(Tab, Fun, NewAttributeList)

Rudolph van Graan rvg@REDACTED
Thu Jul 6 20:15:01 CEST 2006


Hi Andreas,

On 06 Jul 2006, at 7:46 PM, Trap Exit wrote:

>
> The problem is that I have been thought to to assume that records  
> are tuples.

Your assumption is correct.

> You cant have a record name with two definitions, if you have  
> diffrent name, you will have to enter the new recordnam into the  
> databas.

The record definition is not stored in a/the database. Mnesia  
translates the record tuple into an internal format based on the  
schema of the table. The purpose of the transform function is to give  
you an opportunity of changing this schema and at the same time to  
update all the old records to the new specification. If your function  
does not change the records to the new format, they will still be  
stored in mnesia in the old format, with the additional problem that  
your new record definition and mnesia's is now out of sync. The  
moment you change the record definition and recompile, all your code  
will understand the new format. But mnesia won't. This is the purpose  
of the transform functions.

> * When changeing the recodord defintion for at mnesia table change  
> the record name, or

No. use the same record name.

> * Use the tuple definition of records. The code will only be used  
> once so who cares, or

You will probably have to, as when you run this function *your*  
definition has already changed, but mnesia's has not. Match on the  
old record as a tuple and populate the new record. Something like this:

{record, A, B, C} = OldRecord,
NewRecord = #record{a = A, b = B, c = C, d = 123},
NewRecord.

Rudolph van Graan

Telecommunications Specialist
Pattern Matched Technologies

E-Mail:  rvg@REDACTED
Mobile:  +27 83 390 7767
Fax:     +27 12 667 5342
Web:     www.patternmatched.com



More information about the erlang-questions mailing list