我正在使用钩子在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中找不到这样的异常!!
答案 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")).