mnesia db dir
Ulf Wiger (AL/EAB)
ulf.wiger@REDACTED
Sun Jul 10 17:45:58 CEST 2005
Róbert Balogh wrote:
>
> The first question is it possible to set the path of the
> mnesia db from "code". I mean is there other way than erl
> -sname nodename -mnesia dir '"dirpath"'?
You can use application:set_env(mnesia, dir, "...").
You should do this after loading the mnesia application,
but before starting it.
This is not something you should make a habit out of.
application:set_env/3 is mainly there for software upgrade.
A more structured way to do it (if you don't want to pass
it as a command-line parameter) is to use a sys.config
file. This is when you use the sasl framework to start
your system.
> I wrote a small code for learning mnesia and I take a big
> "discovery". It's not possible to insert any record in the
> table, if the table name is different that the name of his record.
> Here is my example:
You can use the option {record_name, rPerson} when creating
the table. Mnesia will then verify that all objects inserted
in 'table' are of the type #rPerson{} (as defined by the
combination of the 'record_name' and 'attributes' options.
/Uffe
>
> -module(ex_mnesia).
>
> -export([start/0]).
>
> -export([insert/1]).
>
> -record(rPerson,{name = [],
> city = []}).
>
>
> start()->
> mnesia:create_schema([node()]),
> mnesia:start(),
>
> mnesia:create_table(table,[{attributes,record_info(fields,rPerson)},
> {disc_copies,[node()]}]).
>
>
> insert(Value)->
> Fun = fun()->
> mnesia:write(table,#rPerson{name = Value},write)
> end,
> mnesia:transaction(Fun).
>
> After calling insert I got this in the erlang shell:
> (a@REDACTED)5> ex_mnesia:insert(aa).
> {aborted,{bad_type,{rPerson,aa,[]}}}
>
> If I change the name of table to rPerson it's possible to
> insert records in the table. So is that true that no way to
> set different name the table as his record name or I did
> something wrong?
>
> Here is what I got after change table name:
> (a@REDACTED)3> ex_mnesia:insert(aa).
> {atomic,ok}
>
>
> thanks a lot the answers,
>
> br,
> /Robi
>
>
>
>
More information about the erlang-questions
mailing list