| Author |
Message |
|
| Guest |
Posted: Wed Apr 16, 2008 11:20 pm |
|
|
|
Guest
|
Hoi All,
This is the erlang code to create the database:
-module(mydb).
-compile(export_all).
-include("/usr/local/lib/erlang/lib/stdlib-1.15.2/include/qlc.hrl").
-record(names, {index, first_name, last_name}).
init() ->
mnesia:create_schema([jil@deneb]),
mnesia:start(),
mnesia:create_table(names,
[{disc_copies, [jil@deneb]},
{attributes,
record_info(fields,names)}]).
insert(Index, Artist, Title) ->
Fun = fun() ->
mnesia:write(
#names{index=Index,
first_name=Artist,
last_name=Title})
end,
mnesia:transaction(Fun).
select(Index) ->
Fun = fun() ->
mnesia:read({names, Index})
end,
{atomic, [Row]}=mnesia:transaction(Fun),
[Row#names.first_name, Row#names.last_name].
erl -sname jil -mnesia dir '"/yaws/www/db2"'
I compiled "mydb.erl" and I run it. It creates the database "db2" where
I have inserted in it some records and it works in local.
And this the file "m.yaws":
<erl>
out(A) ->
mydb:init(),
[A1,A2]=mydb:select(1),
{html, io_lib:format("Name: ~p, ~p",[A1,A2])}.
</erl>
Yaws is run this way:
yaws -M "/yaws/www/db2"
Running Yaws-1.76 + Erlang R12-2 on Linux Slackware
And this is the best I have got
Internal error, yaws code crashed
ERROR erlang code crashed:
File: /yaws/www/m.yaws:1
Reason: {{badmatch,{aborted,{no_exists,names}}},
[{mydb,select,1},
{m3,out,1},
{yaws_server,deliver_dyn_part,8},
{yaws_server,aloop,3},
{yaws_server,acceptor0,2},
{proc_lib,init_p,5}]}
Req: {http_request,'GET',{abs_path,"/m.yaws"},{1,1}}
Any hint, any help?
Thank you.
--
***
Jilani KHALDI
http://www.dotpas.org
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu Apr 17, 2008 5:30 am |
|
|
|
Guest
|
Hi Jilani
First I think you need to start yaws with the same nodename as you created the
schema, try to add "-sname jil" to your yaws start line.
Second you can not create the same schema twice I beleive, so remove
mnesia:create_schema from your init fun and put it separate so you do not
call it from your out/1 function.
Regards
Mikael
Thursday 17 April 2008 01:18:29 Jilani Khaldi wrote:
> Hoi All,
> This is the erlang code to create the database:
> -module(mydb).
> -compile(export_all).
> -include("/usr/local/lib/erlang/lib/stdlib-1.15.2/include/qlc.hrl").
>
> -record(names, {index, first_name, last_name}).
>
> init() ->
> mnesia:create_schema([jil@deneb]),
> mnesia:start(),
> mnesia:create_table(names,
> [{disc_copies, [jil@deneb]},
> {attributes,
> record_info(fields,names)}]).
>
> insert(Index, Artist, Title) ->
> Fun = fun() ->
> mnesia:write(
> #names{index=Index,
> first_name=Artist,
> last_name=Title})
> end,
> mnesia:transaction(Fun).
>
> select(Index) ->
> Fun = fun() ->
> mnesia:read({names, Index})
> end,
> {atomic, [Row]}=mnesia:transaction(Fun),
> [Row#names.first_name, Row#names.last_name].
>
> erl -sname jil -mnesia dir '"/yaws/www/db2"'
>
> I compiled "mydb.erl" and I run it. It creates the database "db2" where
> I have inserted in it some records and it works in local.
>
> And this the file "m.yaws":
> <erl>
> out(A) ->
> mydb:init(),
> [A1,A2]=mydb:select(1),
> {html, io_lib:format("Name: ~p, ~p",[A1,A2])}.
> </erl>
>
> Yaws is run this way:
> yaws -M "/yaws/www/db2"
> Running Yaws-1.76 + Erlang R12-2 on Linux Slackware
>
> And this is the best I have got
>
> Internal error, yaws code crashed
> ERROR erlang code crashed:
> File: /yaws/www/m.yaws:1
> Reason: {{badmatch,{aborted,{no_exists,names}}},
> [{mydb,select,1},
> {m3,out,1},
> {yaws_server,deliver_dyn_part,8},
> {yaws_server,aloop,3},
> {yaws_server,acceptor0,2},
> {proc_lib,init_p,5}]}
> Req: {http_request,'GET',{abs_path,"/m.yaws"},{1,1}}
>
> Any hint, any help?
> Thank you.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu Apr 17, 2008 6:02 am |
|
|
|
Guest
|
Mikael Karlsson wrote:
> Hi Jilani
> First I think you need to start yaws with the same nodename as you created the
> schema, try to add "-sname jil" to your yaws start line.
It is already there.
>> erl -sname jil -mnesia dir '"/yaws/www/db2"'
> Second you can not create the same schema twice I beleive, so remove
> mnesia:create_schema from your init fun and put it separate so you do not
> call it from your out/1 function.
The error is:
"Reason: {{badmatch,{aborted,{no_exists,names}}}"
which means that the table "names" does not exist, or, explicitly, it
can't see it. But the table is in the databse "db2" and it does exist
because I can use it from the interpreter. For example:
mydb:select(1). gives the expected result.
However thank you.
--
***
Jilani KHALDI
http://www.dotpas.org
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| bjnortier |
Posted: Thu Apr 17, 2008 8:27 am |
|
|
|
Joined: 30 Aug 2007
Posts: 9
|
Hi Jilani
I've encountered a similar problem while trying to automate my unit
testing that uses mnesia.
The "no_exists" error seems to occur because mnesia takes a
non-trivial amount of time to start up in the background, and there is
simply not enough time between the :init() and :select() calls for
this to happen.
Adding a small delay seemed to help with my problems, but subsequently
I've found the mnesia:wait_for_tables() function that might work
(although I haven't tried it out yet...)
That being said, Mikael is right in saying that you should create your
schema only once and try and initialise mnesia when you start up yaws
(and not in each page request) You do that with the -r flag.
Hope this helps
Benjamin
http://21ccw.blogspot.com
bjnortier@gmail.com
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu Apr 17, 2008 10:33 am |
|
|
|
Guest
|
> The "no_exists" error seems to occur because mnesia takes a
> non-trivial amount of time to start up in the background, and there is
> simply not enough time between the :init() and :select() calls for
> this to happen.
>
> Adding a small delay seemed to help with my problems, but subsequently
> I've found the mnesia:wait_for_tables() function that might work
> (although I haven't tried it out yet...)
I have add "mnesia:wait_for_tables(names,infinite)" but i didn't help.
I have seen from the interactive Yaws that mnesia is running doing
"mnesia:info".
>
> That being said, Mikael is right in saying that you should create your
> schema only once and try and initialise mnesia when you start up yaws
> (and not in each page request) You do that with the -r flag.
Yes he does, and in fact Mnesia now starts only once.
> Hope this helps
No, it didn't.
Other hints?
--
***
Jilani KHALDI
http://www.dotpas.org
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| tobbe |
Posted: Thu Apr 17, 2008 11:09 am |
|
|
|
User
Joined: 19 Jan 2005
Posts: 274
Location: Stockholm, Sweden
|
Hi,
The slightly modified program I have attached works.
Start it like this:
# mkdir tmp
# erl -mnesia dir tmp -sname tobbe % change SNAME at will
1> mydb:init(),mydb:select(1).
["Bruce Springsteen","The River"]
Note: As said earlier, start mnesia and yaws at startup time.
Have a look here for a good start:
http://blog.socklabs.com/2008/04/a_restful_web_service_demo_in/
Or look into the db_adm.erl file in the eblog app. over at:
http://www.tornkvist.org/gitweb
Just to get some ideas on how to do things.
Cheers, Tobbe
Jilani Khaldi wrote:
> > The "no_exists" error seems to occur because mnesia takes a
> > non-trivial amount of time to start up in the background, and there is
> > simply not enough time between the :init() and :select() calls for
> > this to happen.
> >
> > Adding a small delay seemed to help with my problems, but subsequently
> > I've found the mnesia:wait_for_tables() function that might work
> > (although I haven't tried it out yet...)
> I have add "mnesia:wait_for_tables(names,infinite)" but i didn't help.
> I have seen from the interactive Yaws that mnesia is running doing
> "mnesia:info".
> >
> > That being said, Mikael is right in saying that you should create your
> > schema only once and try and initialise mnesia when you start up yaws
> > (and not in each page request) You do that with the -r flag.
> Yes he does, and in fact Mnesia now starts only once.
>
> > Hope this helps
> No, it didn't.
> Other hints?
>
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu Apr 17, 2008 11:53 am |
|
|
|
Guest
|
Torbjorn Tornkvist wrote:
> Hi,
>
> The slightly modified program I have attached works.
[..]
I have just solved it this way:
yaws --sname jil -M "yaws/ww/db2" -D
and it works.
> 1> mydb:init(),mydb:select(1).
> ["Bruce Springsteen","The River"]
2> mydb:init(),mydb:select(2).
["Bruce Springsteen","Tunnel of love"]
3> mydb:init(),mydb:select(3).
["Bruce Springsteen","Nebraska"]
...
Nice links. Thank you!
--
***
Jilani KHALDI
http://www.dotpas.org
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu Apr 17, 2008 7:17 pm |
|
|
|
Guest
|
I changed the "select" function putting a guard:
select(Index) ->
Fun = fun() ->
case mnesia:read({names, Index}) of
[Row] -> [Row#names.first_name, Row#names.last_name]
; _ -> mnesia:abort(not_found)
end
end,
mnesia:transaction(Fun).
This code works only if "Index" exists otherwise it raised the error:
ERROR erlang code crashed:
File: /yaws/www/mnesia.yaws:1
Reason: {{badmatch,{atomic,[]}},
[{mydb,select,1},
{m2,out,1},
{yaws_server,deliver_dyn_part,8},
{yaws_server,aloop,3},
{yaws_server,acceptor0,2},
{proc_lib,init_p,5}]}
Req: {http_request,'POST',{abs_path,"/mnesia.yaws"},{1,1}}
and this is mnesia.yaws
<erl>
kv(K,L) ->
{value, {K, V}} = lists:keysearch(K,1,L), V.
out(A) ->
L = yaws_api:parse_post(A),
Idx = list_to_integer(kv("idx", L)),
[A1,A2]=mydb:select(Idx),
{html, io_lib:format("Name: ~p, ~p",[A1,A2])}.
</erl>
I can't understand where is the error. In "mydb.erl", in "mnesia.yaws"
or elsewhere? This is the last doubt for today
Thank you.
--
***
Jilani KHALDI
http://www.dotpas.org
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Fri Apr 18, 2008 5:51 am |
|
|
|
Guest
|
Jilani Khaldi wrote:
> Mikael Karlsson wrote:
> > Hi Jilani
> > First I think you need to start yaws with the same nodename as you
> > created the schema, try to add "-sname jil" to your yaws start line.
>
> It is already there.
>
> >> erl -sname jil -mnesia dir '"/yaws/www/db2"'
> >
No, that is when you start the erlang shell, the YAWS start line starts
with "yaws":
yaws -sname jil ...
Seems you found it out yourself later on from what I can read from the rest of
the discussion thread and that I missed an extra dash; --sname
Cheers
Mikael
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| tobbe |
Posted: Fri Apr 18, 2008 7:37 am |
|
|
|
User
Joined: 19 Jan 2005
Posts: 274
Location: Stockholm, Sweden
|
I suggest you try and run only your DB stuff from an erlang
shell, similar to what I showed earlier.
The Error indicates that the crash is in the mydb:select/1
function because of a badmatch. But the code look ok i think.
mydb:select/1 should return either: {atomic,[_,_]} or: {aborted,not_found}
So I can't see how you could get: {atomic,[]}
Are you sure you have recompiled and reloaded ?
Cheers, Tobbe
Jilani Khaldi wrote:
> I changed the "select" function putting a guard:
>
> select(Index) ->
> Fun = fun() ->
> case mnesia:read({names, Index}) of
> [Row] -> [Row#names.first_name, Row#names.last_name]
> ; _ -> mnesia:abort(not_found)
> end
> end,
> mnesia:transaction(Fun).
>
> This code works only if "Index" exists otherwise it raised the error:
> ERROR erlang code crashed:
> File: /yaws/www/mnesia.yaws:1
> Reason: {{badmatch,{atomic,[]}},
> [{mydb,select,1},
> {m2,out,1},
> {yaws_server,deliver_dyn_part,8},
> {yaws_server,aloop,3},
> {yaws_server,acceptor0,2},
> {proc_lib,init_p,5}]}
> Req: {http_request,'POST',{abs_path,"/mnesia.yaws"},{1,1}}
>
> and this is mnesia.yaws
> <erl>
> kv(K,L) ->
> {value, {K, V}} = lists:keysearch(K,1,L), V.
>
> out(A) ->
> L = yaws_api:parse_post(A),
> Idx = list_to_integer(kv("idx", L)),
> [A1,A2]=mydb:select(Idx),
> {html, io_lib:format("Name: ~p, ~p",[A1,A2])}.
> </erl>
>
> I can't understand where is the error. In "mydb.erl", in "mnesia.yaws"
> or elsewhere? This is the last doubt for today
> Thank you.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Fri Apr 18, 2008 10:07 am |
|
|
|
Guest
|
|
| 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
|
|
|