Debugging ErlyDB and MySQL

烂漫一生 提交于 2019-12-11 01:54:07

问题


I am experimenting with ErlyDB in a non-erlyweb environment and I am not having much luck.

I have a 'Thing' table for testing, and a corresponding Thing module:

-module(thing).
-export([table/0, fields/0]).

table() ->
     thing.
fields() ->
    [name, value].

The module itself works - I can query the database fine using ([Thing] = thing:find({name, '=', "test"})).

When I try and save a new record, however things aren't so good.

I consistently see the following error:

mysql_conn:426: fetch <<"BEGIN">> (id <0.97.0>)
mysql_conn:426: fetch <<"INSERT INTO thing(value,name) VALUES ('vtha','blah')">> (id <0.97.0>)
mysql_conn:426: fetch <<"ROLLBACK">> (id <0.97.0>)
** exception exit: {{'EXIT',{badarg,[{erlang,hd,[[]]},
                                     {erlydb_base,'-do_save/1-fun-0-',4},
                                     {mysql_conn,do_transaction,2},
                                     {mysql_conn,loop,1}]}},
                    {rollback_result,{updated,{mysql_result,[],[],0,[]}}}}
     in function  erlydb_base:do_save/1
     in call from erlydb_base:hook/4
     in call from test_thing:test/0
        called as test_thing:test()

The table exists, the credentials work, and the SQL itself is fine, as I can execute the command directly on the database.

The code I am using to save is:

erlydb:start(mysql, Database),
Thing = thing:new(<<"hello">>, <<"world">>),
thing:save(Thing),

Is there something I am missing? Is there some way of viewing some more helpful error messages from the database?


回答1:


Looking at the source of erlydb_base, the exception happens when erlydb calls your thing module's db_pk_fields() function. That function should return a list, but apparently it doesn't.




回答2:


I can confirm that altering the code in erlydb.erl fixes this problem (from this reference on the mailing list).

Change Line 561 of erlydb.erl from

lists:map(fun({_Name, _Atts} = F) -> F;
      (Name) -> {Name, []}
      end, lists:usort(DefinedFields)),

To:

lists:map(fun({_Name, _Atts} = F) -> F;
      (Name) -> {Name, []}
      end, DefinedFields),


来源:https://stackoverflow.com/questions/1228893/debugging-erlydb-and-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!