Question

I am trying to create mnesia table from Erlang shell. I got error and the same error for the below syntax copied from mnesia help documents.

mnesia:create_table(employee,
    [{attributes, record_info(fields, employee)}]).

got the error

record employee undefined

tried various combinations, getting same error. mnesia already started.

Was it helpful?

Solution 2

You can try rd(employee, {emp_no, name, salary, sex, phone, room_no}). in the erlang shell.

rd(RecordName, RecordDefinition) Defines a record in the shell. RecordName is an atom and RecordDefinition lists the field names and the default values. Usually record definitions are made known to the shell by use of the rr commands described below, but sometimes it is handy to define records on the fly.

Please see this link:http://www.erlang.org/doc/man/shell.html

OTHER TIPS

You need to have the record employee defined before you can do record_info on it. In the shell use can use rr(FileName). command which will find all the record definitions in the file and remember them. In a module you would either define the record directly in the module or include a file which contains the record definition.

The reason for having to do this special handling in the shell is that records are purely a compile-time feature so a record definition doesn't really "exist" anywhere.

EDIT: If you want to define the record directly in shell then you can't use the standard -record(...). syntax. That is only valid in modules. The shell sees that as a call to the record/2 function. You need to use the rd shell command. It your case it would become:

3> rd(employee, {emp_no, name, salary, sex, phone, room_no}).
employee
4> record_info(fields, employee).
[emp_no,name,salary,sex,phone,romm_no]
5> 

Then record_info works. If you already have the record definitions in a file then use the shell rr(File). command instead as it is easier. I think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top