Debug ErlyDB and MySQL

I am experimenting with ErlyDB in an environment other than erlyweb, and I'm not very lucky.

I have a table "Thing" for testing and the corresponding Thing module:

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

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

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

When I try to save a new record, however, everything is not so good.

I constantly 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 and SQL itself are in order, since I can execute the command directly in the database.

The code I use to save:

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

Is there something I am missing? Is there a way to view more useful error messages from the database?

+2
source share
2

, erlydb.erl ( ).

561 erlydb.erl

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),
+1

source erlydb_base, , erlydb db_pk_fields(). , , -, .

+3

Source: https://habr.com/ru/post/1714388/


All Articles