调试 ErlyDB 和 MySQL

发布于 2024-07-30 01:38:47 字数 1362 浏览 3 评论 0原文

我正在非 erlyweb 环境中试验 ErlyDB,但运气不佳。

我有一个用于测试的“Thing”表和相应的 Thing 模块:

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

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

模块本身可以工作 - 我可以使用 ([Thing] = thing:find({name, '=', "test" }))。

然而,当我尝试保存新记录时,情况不太好。

我始终看到以下错误:

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()

表存在,凭据有效,并且 SQL 本身很好,因为我可以直接在数据库上执行命令。

我用来保存的代码是:

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

我缺少什么吗? 是否有某种方法可以从数据库中查看一些更有用的错误消息?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

茶底世界 2024-08-06 01:38:47

查看 erlydb_base 的来源,异常发生在 erlydb调用您的事物模块的 db_pk_fields() 函数。 该函数应该返回一个列表,但显然没有。

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.

弱骨蛰伏 2024-08-06 01:38:47

我可以确认更改 erlydb.erl 中的代码可以解决此问题(来自 邮件列表上的此引用)。

将 erlydb.erl 的第 561 行从改为

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

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

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),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文