ejabberd
ejabberd copied to clipboard
Why ejabberd_sql does not support dynamic table name insertion
I tried spool sub-table processing, and found that ejabberd_sql can't? SQL_INSERT, the following is my code
insert_into_spool({LUser, LServer, LStatus, XML}) ->
{Year, Month, _} = erlang:timestamp(),
TableName = lists:concat(["spool_", integer_to_list(Year), "_", integer_to_list(Month)]),
?INFO_MSG("TableName == ~s", [TableName]),
case ejabberd_sql:sql_query(
LServer,
?SQL_INSERT(
TableName,
["username=%(LUser)s",
"server_host=%(LServer)s",
"status=%(LStatus)s",
"xml=%(XML)s"])) of
{updated, _} ->
ok;
_ ->
{error, db_failure}
end.
Those ?SQL* macros are converted to erlang code, that's why they only accept literals - this needs to be expanded to code, before rest of that code is run. You will probably need to switch to using literal string in this case.