25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

* src/odbc/odbc_queries.erl: replaced string:join/2 function.

Removed ugly "catch" statement from update_t/4.
WARNING: this change requires last version of mysql driver.
You can update it from ejabberd-modules repository.

SVN Revision: 1762
This commit is contained in:
Evgeniy Khramtsov 2008-12-29 09:26:20 +00:00
parent 85fdf7cb25
commit 5a5ab955cb
2 changed files with 21 additions and 11 deletions

View File

@ -4,6 +4,11 @@
an SQL transaction exceeds number of restarts. Also rollbacks
this transaction to prevent deadlocks.
* src/odbc/odbc_queries.erl: replaced string:join/2 function.
Removed ugly "catch" statement from update_t/4.
WARNING: this change requires last version of mysql driver.
You can update it from ejabberd-modules repository.
2008-12-28 Mickael Remond <mremond@process-one.net>
* src/ejabberd_c2s.erl: We should allow use of bare resource in from by

View File

@ -88,6 +88,14 @@
-define(generic, true).
-endif.
%% Almost a copy of string:join/2.
%% We use this version because string:join/2 is relatively
%% new function (introduced in R12B-0).
join([], _Sep) ->
[];
join([H|T], Sep) ->
[H, [[Sep, X] || X <- T]].
%% -----------------
%% Generic queries
-ifdef(generic).
@ -101,17 +109,14 @@ update_t(Table, Fields, Vals, Where) ->
Fields, Vals),
case ejabberd_odbc:sql_query_t(
["update ", Table, " set ",
string:join(UPairs, ", "),
join(UPairs, ", "),
" where ", Where, ";"]) of
{updated, 1} ->
ok;
_ ->
%% The 'catch' herein is used because mysql returns
%% affected rows (not matched as in postgresql).
%% FIXME: need to find more suitable solution.
catch ejabberd_odbc:sql_query_t(
["insert into ", Table, "(", string:join(Fields, ", "),
") values ('", string:join(Vals, "', '"), "');"])
ejabberd_odbc:sql_query_t(
["insert into ", Table, "(", join(Fields, ", "),
") values ('", join(Vals, "', '"), "');"])
end.
%% F can be either a fun or a list of queries
@ -346,7 +351,7 @@ update_roster(_LServer, Username, SJID, ItemVals, ItemGroups) ->
ejabberd_odbc:sql_query_t(
["insert into rostergroups("
" username, jid, grp) "
" values ('", string:join(ItemGroup, "', '"), "');"])
" values ('", join(ItemGroup, "', '"), "');"])
end,
ItemGroups).
@ -358,13 +363,13 @@ update_roster_sql(Username, SJID, ItemVals, ItemGroups) ->
" username, jid, nick, "
" subscription, ask, askmessage, "
" server, subscribe, type) "
" values ('", string:join(ItemVals, "', '"), "');"],
" values ('", join(ItemVals, "', '"), "');"],
["delete from rostergroups "
" where username='", Username, "' "
" and jid='", SJID, "';"]] ++
[["insert into rostergroups("
" username, jid, grp) "
" values ('", string:join(ItemGroup, "', '"), "');"] ||
" values ('", join(ItemGroup, "', '"), "');"] ||
ItemGroup <- ItemGroups].
roster_subscribe(_LServer, Username, SJID, ItemVals) ->
@ -520,7 +525,7 @@ set_privacy_list(ID, RItems) ->
"match_presence_out "
") "
"values ('", ID, "', '",
string:join(Items, "', '"), "');"])
join(Items, "', '"), "');"])
end, RItems).
del_privacy_lists(LServer, Server, Username) ->