I'm writing a module in ejabberd using hooks. In it, I fire a SQL query as follow:-
?INFO_MSG("Packet Type:- `~p` ~n ~n ~n", [sql_queries:get_privacy_list_names_t("praful")]);
sql_queries is another module in ejabberd and get_privacy_list_names_t is the function in it.
get_privacy_list_names_t(LUser) ->
ejabberd_sql:sql_query_t(
?SQL("select @(name)s from privacy_list"
" where username=%(LUser)s")).
It returns an error saying:-
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}]}]}
What exactly is the error?
It says, badrecord. What is this? I couldnt find such exception in erlang !!
ejabberd_sql.erl, the code tries to access a record field in a variable, but that variable doesn't actually contain astaterecord. (The error message doesn't say what it actually contained.) - legosciacase State#state.db_type of- it tries to access thedb_typefield in thestaterecord contained in the variableState, but ifStatedoesn't actually contain astaterecord, you'll get abadrecorderror. (As for whyStatehas the wrong value, I have no idea, I'm afraid.) - legosciasql_queries:get_privacy_list_namesinstead ofsql_queries:get_privacy_list_names_t, as the functions with the_tsuffix should only be called from within an SQL transaction. - legoscia