Ejabberd - 处理SQL查询时出错

时间:2017-06-13 06:34:21

标签: sql erlang ejabberd

我正在使用钩子在ejabberd中编写一个模块。在其中,我按如下方式触发SQL查询: -

?INFO_MSG("Packet Type:- `~p` ~n ~n ~n", [sql_queries:get_privacy_list_names_t("praful")]);

sql_queries是ejabberd中的另一个模块,get_privacy_list_names_t是其中的函数。

get_privacy_list_names_t(LUser) ->
    ejabberd_sql:sql_query_t(
      ?SQL("select @(name)s from privacy_list"
           " where username=%(LUser)s")).

它返回错误说: -

11:50:34.790 [error] Internal error while processing SQL query: {error,{badrecord,state},[{ejabberd_sql,sql_query_internal,1,[{file,"src/ejabberd_sql.erl"},{line,526}]},{ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,180}]},{mod_sunshine,user_receive_packet,1,[{file,"src/mod_sunshine.erl"},{line,27}]},{ejabberd_hooks,safe_apply,4,[{file,"src/ejabberd_hooks.erl"},{line,380}]},{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,364}]},{ejabberd_c2s,process_info,2,[{file,"src/ejabberd_c2s.erl"},{line,231}]},{ejabberd_hooks,safe_apply,4,[{file,"src/ejabberd_hooks.erl"},{line,380}]},{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,364}]}]}

究竟是什么错误?

它说,badrecord。这是什么?我在erlang中找不到这样的异常!!

1 个答案:

答案 0 :(得分:1)

正如@legoscia所提到的,sql_queries:get_privacy_list_names而不是sql_queries:get_privacy_list_names_t,因为带有_t后缀的函数只能在SQL事务中调用。

functionname(LServer, Param) ->
    ejabberd_sql:sql_query(
        LServer,
        ?SQL("select @(column)s from table "
             "where column=%(Param)s")).